How to change spring -websocket to interact with the broker via MQTT instead of STOMP?

I am creating a spring -websocket application that currently uses RabbitMQ as a message broker through the STOMP protocol. The rest of our organization mainly uses IBM Websphere MQ as a message broker, so we would like to convert it from RabbitMQ. However, Websphere MQ does not support the STOMP protocol, which is spring -websocket by default. MQTT looks like the easiest supported protocol to use. Ideally, our front-end web clients will continue to use STOMP, but I am also fine with porting them to MQTT, if necessary.

What classes do I need to rewrite to make the spring-websocket interface with the broker via MQTT instead of STOMP? This article provides some general guidelines that I should extend AbstractMessageBrokerConfiguration , but I don’t know where to start.

I am currently using standard configuration methods: registry.enableStompBrokerRelay and registerStompEndpoints in AbstractWebSocketMessageBrokerConfigurer

+5
source share
2 answers

Ryan has some good pointers.

The main work will be to create a replacement for StompBrokerRelayMessageHandler using MqttBrokerMessageHandler, which not only talks to the MQTT broker, but also adapts the STOMP client frames to MQTT and vice versa. The protocols are similar enough that you can find a common language, but you won't know until you try.

Please note that we had plans for supporting MQTT https://jira.spring.io/browse/SPR-12581 , but the key problem was that SockJS, which is required over the Internet for backup support does not support binary messages.

0
source

Here is my hit on this after looking at the spring -websocket source code:

  • Change WebSocketConfig:

    • Delete @EnableWebSocketMessageBroker
    • Add new annotation: @EnableMqttWebSocketMessageBroker
  • Create an MqttBrokerMessageHandler that extends AbstractBrokerMessageHandler - suppose we copy and edit StompBrokerRelayMessageHandler

  • Create a new class that imports EnableMqttWebSocketMessageBroker: DelegatingMqttWebSocketMessageBrokerConfiguration
  • DelegationMqttWebSocketMessageBrokerConfiguration directly extends AbstractMessageBrokerConfiguration and is routed to MqttBrokerMessageHandler
0
source

Source: https://habr.com/ru/post/1234223/


All Articles