Java Spring Download: SimpMessagingTemplate send messages are not accepted by Stomp endpoints

I can't get the Spring message sample to work in unit tests using the SimpMessagingTemplate to send messages to endpoints.

I followed the instructions below: https://spring.io/guides/gs/messaging-stomp-websocket/

So far, my controller is as follows:

@Data @NoArgsConstructor @AllArgsConstructor public static class Message { private Long id; private String value; private long time; } @MessageMapping("/message") @SendTo("/topic/response") public Message slowEndpont(Message message) throws Exception { Thread.sleep(3000); // simulated delay System.err.println("Message Received: " + message); return new Message(message.id, "Hello Client", System.currentTimeMillis()); } 

My Unit Test is now trying to send a message:

 @Autowired SimpMessagingTemplate messageTemplate; @Test public void sendMessage() throws Exception { System.err.println("** Sending messages..."); messageTemplate.convertAndSend("/app/message", new MessageController.Message(1L, "Hello Server", System.currentTimeMillis())); messageTemplate.convertAndSend("/topic/message", new MessageController.Message(1L, "Hello Server", System.currentTimeMillis())); messageTemplate.convertAndSend("/queue/message", new MessageController.Message(1L, "Hello Server", System.currentTimeMillis())); messageTemplate.convertAndSend("/message", new MessageController.Message(1L, "Hello Server", System.currentTimeMillis())); System.err.println("** Messages send!"); Thread.sleep(1500); } 

A sample full code is here: https://github.com/puel/training/tree/master/messaging

So far so good. All messages are sent. But never received. I traced it and the MessageTemplate registry is empty. But why?

This issue also seems too close: Send a message to all clients via SimpMessagingTemplate in ServletContextListener

But using MessageSendingOperations doesn't help either.

Thanks,

Floor

+6
source share

All Articles