Custom assignment with RabbitMQ

I am trying to use RabbitMQ as a broker in my project and I want to assign a destination queue when a socket is opened on the client side. Something like this:

I managed to do it with help SimpleBroker

, however, when I try to do it with help StompBrokerRelay

, I cannot define the queue on RabbitMQ and stop receiving messages on the client ( ).

This is how I do it:


public class FeedController {

private SimpMessageSendingOperations template;

    @RequestMapping(value = "/feed",  method = RequestMethod.POST, consumes = "application/json")
    public Reference getLeankrReference(@RequestBody Reference ref)
        this.template.convertAndSendToUser(ref.getChannelId(), "/topic/feed", ref);
        return ref;


Websocket config:

public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {

    public void configureMessageBroker(MessageBrokerRegistry config)


    public void registerStompEndpoints(StompEndpointRegistry registry) {



        function connect() {
        var socket = new SockJS('/ws/vision');
        var channel = document.getElementById('name').value;
        stompClient = Stomp.over(socket);

        stompClient.connect({}, function(frame) {
            console.log('Connected: ' + frame);
            stompClient.subscribe('/user/' + channel + '/feed', function(message) {


I know I am missing something. Maybe some kind of brokerage config?

Thank you in advance!


source to share

1 answer

Finally I figured out what I was missing!

Websocket config:

I only assigned a queue of topics. In this case, I also need a queue queue as soon as I want to assign it to a specific user / channel.

config.enableStompBrokerRelay("/queue/", "/topic/");



I didn't mean the type of queue I wanted to use.

stompClient.subscribe('/user/queue/feed', function(content) {

But that was not enough. Lack of correct security configuration.

Something like that,

Security configuration:

protected void configure(HttpSecurity http) throws Exception {
            new XFrameOptionsHeaderWriter(

protected void configure(AuthenticationManagerBuilder auth) throws Exception {


With that, I added a login page. It's not obligatory. You just need to make sure the password parameter is used for authentication.

Now that Rabbit knows the user / channel, he can send queues to specific destinations.



All Articles