Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

278
Views
Los canales de Django con Spring Boot Websockets (StompSession) no funcionan

Hola, queremos usar Django solo para ejecutar el código python y usar canales para los resultados. Implementé todo lo que los websockets no funcionan como deberían. Si trato de enviar algo desde nuestra interfaz Angular a Django, funciona bien. Y de lo contrario, nuestros Spring Boot StompSession Websockets funcionan bien con otras aplicaciones Spring Boot y Angular.

Pero Django 3.1.3 y Spring Boot 2.3.3 no. Además, se utilizan los canales 3.0.2,channels-redis 3.2.0 y un contenedor docker de redis 6.

Lo que puedo ver en los registros del servidor Django:

 WebSocket HANDSHAKING /ws/card-detection/ [127.0.0.1:53209] i'm in connect method WebSocket CONNECT /ws/card-detection/ [127.0.0.1:53209] i'm in receive method text_data: CONNECT

Esto se ejecuta tan pronto como llega la solicitud de websocket.

El consumidor de django (sin las impresiones que se registran arriba):

 class MyConsumer(WebsocketConsumer): groups = ["broadcast"] def connect(self): self.accept() def receive(self, text_data=None, bytes_data=None): self.send(text_data="Hello world!") def disconnect(self, close_code): pass

Desde Spring Boot enviamos una imagen codificada en base64. Pero también todo lo demás no funciona. Como puede ver, text_data es solo CONNECT .

Bota de primavera:

 StompSessionHandler sessionHandler = new CardDetectionStompSessionHandler(request, user, webSocketMessagingService); createStompClient().connect(djangoServiceWSPath, sessionHandler); } private WebSocketStompClient createStompClient() { WebSocketClient client = new StandardWebSocketClient(); WebSocketStompClient stompClient = new WebSocketStompClient(client); stompClient.setMessageConverter(new MappingJackson2MessageConverter()); return stompClient; }

El controlador de sesión Stomp para darle una idea de cómo se ve. Debería ir en el método afterConnected() pero nunca irá en ninguno de estos métodos:

 public class CardDetectionStompSessionHandler extends StompSessionHandlerAdapter { private final ImageClassificationRequest request; private final String username; private final String destination = "/card-detection/"; private final WebSocketMessagingService webSocketMessagingService; private StompSession session; public CardDetectionStompSessionHandler( ImageClassificationRequest request, String username, WebSocketMessagingService webSocketMessagingService) { this.request = request; this.username = username; this.webSocketMessagingService = webSocketMessagingService; } @Override public void afterConnected(StompSession session, StompHeaders connectedHeaders) { log.info("Client: New session established: {}", session.getSessionId()); this.session = session; session.subscribe("/user/queue/response", this); log.info("Client: Subscribed to \"/user/queue/response\""); session.send("/app" + destination, request); log.info("Client: Message sent to {}", session.getSessionId()); } @Override public Type getPayloadType(StompHeaders headers) { return ImageClassificationResponse.class; } @Override public void handleFrame(StompHeaders headers, Object payload) { log.info("Client: Message received"); ImageClassificationResponse response = (ImageClassificationResponse) payload; webSocketMessagingService.sendToUser(username, response); if (response.isDone()) { session.disconnect(); log.info("Client: Disconnected."); } } @Override public void handleTransportError(StompSession session, Throwable exception) { log.info("Client: Django is not available"); WebSocketResponse response = new WebSocketResponse(); response.setDisconnect(true); webSocketMessagingService.sendToUser(username, response); } }

Intentamos cambiarlo a un websocket asíncrono en Django pero eso no cambió nada. El self.accept en Djangos connect() no parece enviar una respuesta o la respuesta Spring Boot necesita continuar.

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!