Search code examples
spring-integrationstomp

Spring Integration for SimpMessagingTemplate


I have an MVC project that do the below

@Autowired
SimpMessagingTemplate messagingTemplate;

private void sendAlarmUpdate(AlarmNotify alarmNotify) {
    messagingTemplate.convertAndSend("/topic/notify/alarm",alarmNotify);
}

I am trying to convert this into Spring Integration using int-stomp:outbound-channel-adapter but i am getting exception that the message payload should be array of bytes , i tried converting my object into JSON but still the same , what is the correct way to send a STOMP JSON message from spring-integration

@Bean
public Reactor2TcpStompClient stompClient() {
    Reactor2TcpStompClient stompClient = new Reactor2TcpStompClient("192.168.70.XXX", 61613);

    //stompClient.setMessageConverter(new PassThruMessageConverter());
    ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
    taskScheduler.afterPropertiesSet();
    stompClient.setTaskScheduler(taskScheduler);
    stompClient.setReceiptTimeLimit(5000);
    return stompClient;
 }

@Bean
public StompSessionManager stompSessionManager() {
   Reactor2TcpStompSessionManager stompSessionManager = new Reactor2TcpStompSessionManager(stompClient());
   stompSessionManager.setAutoReceipt(true);
   return stompSessionManager;

}

<int:chain input-channel="stompChannel">
    <!--<int:object-to-json-transformer />-->
    <int-stomp:outbound-channel-adapter stomp-session-manager="stompSessionManager" destination="/topic/notify/alarm1" id="stompAdapter" />
</int:chain>

Solution

  • The problem with STOMP protocol on the wire that it really requires byte[] as message body.

    So, you don't have choice unless convert your JSON into byte[] manually, or provide StringMessageConverter into your stompClient instead of that commented PassThruMessageConverter.