简体   繁体   中英

Spring websocket with STOMP, SOCKJS and ACTIVEMQ

We are integrating spring web sockets into our application and I ran the hello world example and it is amazing that spring wires up everything for us to push server side notifications to the client side.

However I have some simple questions

1) How do the queues get created? I am using ActiveMQ and the queue names are different(eg like greetings-user3n9_jn3i) then what I specify in the destinations for eg

simpMessageSendingOperations.convertAndSend("/test/greeting", new Greeting("Hello Socket Listener!"));

2) Is the destination name different from a queue?

3) I am creating new queues using ActiveMQ console for eg /test1/greeting and sending I am subscribing to them in the client side as shown

var stompClient = null;

connect();

function connect() {
    var socket = new SockJS(stompUrl);
    stompClient = Stomp.over(socket);
    stompClient.connect({}, function(frame) {
        console.log('Connected: ' + frame);
        stompClient.subscribe('/user/queue/greetings', function(greeting){
            alert(greeting);
        });
    });
}

 function disconnect() {
        if (stompClient != null) {
            stompClient.disconnect();
        }
        setConnected(false);
        console.log("Disconnected");
    }

$("#lstnMsgsBtn").click(function() {
    $.ajax({
        url: testUrl,
        type: "POST",
        success: function(data) {

            var queueName = data.queueName;

            stompClient.subscribe(queueName, function(greeting){
                alert(greeting);
            });
        },
        error : function(jqXhr, textStatus, errorThrown) {
            alert(errorThrown);
        }
    });
});

I am unable to subscribe to the queueName, I am pretty sure I am thinking in a wrong way, any pointers will be greatly appreciated.

  1. I have worked with RabbitMq, it their documentation they explain how they parse the destination patterns. I think it is quite similar in active mq. Usually it is like

     /exchange/routingkey 

    The queue will be dynamically generated for each subscriber and bind to exchange via routing key.But you can specify the queue as well. You have to follow the syntax specified by the exchange.

  2. I think above answer this as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM