Hot questions for Using RabbitMQ in sockjs

Question:

I am working on adding live notification in my application

I have done POC with - Spring Boot - Spring WebSocket - SockJS - RabbitMQ STOMP plugin

I read about RabbitMQ Web STOMP and want to do POC of that. But it says Since version 3.7 support for SockJS websocket emulation was removed.

Is there any example for Spring WebSocket + RabbitMQ Web STOMP with or without SockJS.

Please help.

Reference links:

http://www.rabbitmq.com/stomp.html

http://www.rabbitmq.com/web-stomp.html

https://spring.io/guides/gs/messaging-stomp-websocket/


Answer:

@n.sharvarish... first create a websocket configuration class over rabbitmq like this...

@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
    private static final Logger log = LoggerFactory.getLogger(WebSocketConfig.class);
    @Value("${spring.rabbitmq.username}")
    private String userName;
    @Value("${spring.rabbitmq.password}")
    private String password;
    @Value("${spring.rabbitmq.host}")
    private String host;
    @Value("${spring.rabbitmq.port}")
    private int port;
    @Value("${endpoint}")
    private String endpoint;
    @Value("${destination.prefix}")
    private String destinationPrefix;
    @Value("${stomp.broker.relay}")
    private String stompBrokerRelay;
    @Override
    public void configureMessageBroker(final MessageBrokerRegistry config) {
        config.enableStompBrokerRelay(stompBrokerRelay).setRelayHost(host).setRelayPort(port).setSystemLogin(userName).setSystemPasscode(password);
        config.setApplicationDestinationPrefixes(destinationPrefix);
    }
    @Override
    public void registerStompEndpoints(final StompEndpointRegistry registry) {
        registry.addEndpoint(endpoint).setAllowedOrigins("*").withSockJS();
    }
}

and then ... use above config class where you want to use .. like this..

@Autowired
SimpMessagingTemplate template

template.convertAndSend(destinationurl, object);

and configure above username and password and all from application.properties

Question:

i hope someone can help me with this issue: I use the Websocket support of Spring. With SockJs and StompJs i subscribe a queue like this:

    var socket = new SockJS(localhost + 'websocket');
    stompClient = Stomp.over(socket);
    stompClient.connect('', '', function(frame) {
        stompClient.subscribe("/user/queue/gotMessage", function(message) {
            gotMessage((JSON.parse(message.body)));
        });
    }, function(error) {
    });

This works really fine with the SimpMessageSendingOperations of Spring. BUT there is one big problem. the Queue name looks like this: gotMessage-user3w4tstcj and its not declared as an auto delete queue, but this is what i want. Otherwise i have 10k of unused queues. In that moment where the queue as no consumer, the queue should be deleted. How can i assume this?


Answer:

had same problem, from the documentation:

RabbitMQ creates auto-delete queues when destinations like /exchange/amq.direct/position-updates are used. So in that case the client could subscribe to /user/exchange/amq.direct/position-updates

remember to add '/exchange/' as a destination prefix in stomp broker relay configuration

Question:

I'm using RabbitMQ, Spring and SockJS. My app generatea many different messages and posts them to rabbitmq via stomp. This generation requires a lot of resources so I want to know is there any subscriptions to rabbitmq and what kind of subscription it is (I need to know routing keys of this subscriptions) to avoid generating unnecessary messages. Is there any possibilities to get this information from Spring or any Java client library?


Answer:

You can find all the information using one or more of the following