Spring SimpMessagingTemplate 集成

Spring Integration for SimpMessagingTemplate

我有一个执行以下操作的 MVC 项目

@Autowired
SimpMessagingTemplate messagingTemplate;

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

我正在尝试使用 int-stomp:outbound-channel-adapter 将其转换为 Spring 集成,但出现异常消息负载应为字节数组,我尝试将我的对象转换为 JSON但还是一样,从 spring-integration

发送 STOMP JSON 消息的正确方法是什么
@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>

STOMP 协议在网络上的问题,它确实需要 byte[] 作为消息正文。

因此,您别无选择,除非手动将您的 JSON 转换为 byte[],或者将 StringMessageConverter 提供给您的 stompClient 而不是注释 [=14] =].