Rabbitmq::Stomp:: unable to subscribe to existing queue

199 views
Skip to first unread message

Ishwarya K

unread,
Oct 31, 2019, 5:19:31 AM10/31/19
to rabbitmq-users
I have a web app, based on spring websocket over stomp. And I'm using Rabbitmq with stomp plug-in. I have a 'topic' type 'exchange' and bounded it with a queue with routing key. 
I am able to send message to the my queue through stompclient. However when i try to subscribe, its creating new queue with given routing key under given exchange. i am not sure what i m missing. I wanna subscribe to an existing queue. Can somebody please help me on this. 


As per the above link, destination type with topic/exchange, creates a new queue and subscribe to it. What is the way to subscribe to an existing queue under 'amq.topic' exchange.



Regards
Ishwarya

Wesley Peng

unread,
Oct 31, 2019, 5:27:17 AM10/31/19
to rabbitm...@googlegroups.com
Ishwarya K wrote:
> What is the way to subscribe to an existing queue under 'amq.topic'
> exchange.
>

Hi,

You could describe the queue name with the existing one when consumer
begins to consume.

regards.

Wesley Peng

unread,
Oct 31, 2019, 5:29:22 AM10/31/19
to rabbitm...@googlegroups.com
sorry I meant to declare the queue name with the existing one.

regard

Ishwarya K

unread,
Oct 31, 2019, 5:34:44 AM10/31/19
to rabbitmq-users
I m subscribing to my queue with its name, however its creating a new queue under the given exchange with routing key.

     stompClient.subscribe("/exchange/wsexchange/test", function (message) {
     console.log("message"+message);  }); 

     stompClient.send("/exchange/wsexchange/test", { "content-type": "application/json" }, JSON.stringify(chatMessage));

Send works perfectly. when i subscribe, new queue is getting create under 'wsexchange' with 'test' as routing key.

Regards
Ishwarya

Wesley Peng

unread,
Oct 31, 2019, 5:37:26 AM10/31/19
to rabbitm...@googlegroups.com
Ishwarya K wrote:
>
> Send works perfectly. when i subscribe, new queue is getting create
> under 'wsexchange' with 'test' as routing key.
>
Hello

what's the consumer code?

regards

Ishwarya K

unread,
Oct 31, 2019, 5:45:39 AM10/31/19
to rabbitmq-users
Below is my javascript code:

function conn(){
var socket = new SockJS('/ws');
stompClient = Stomp.over(socket);

stompClient.connect({}, onConnected, onError);
}

function onConnected() {
           
     stompClient.subscribe("/exchange/wsexchange/test", function (message) {
     console.log("message"+message);  }); 
}

I m just printing the received messages in the console.


Regards
Ishwarya

Wesley Peng

unread,
Oct 31, 2019, 5:51:33 AM10/31/19
to rabbitm...@googlegroups.com
Ishwarya K wrote:
> Below is my javascript code:
>
> function conn(){
> var socket = new SockJS('/ws');
> stompClient = Stomp.over(socket);
>
> stompClient.connect({}, onConnected, onError);
> }
>
> function onConnected() {
>      stompClient.subscribe("/exchange/wsexchange/test", function
> (message) {
>      console.log("message"+message);  });
> }
>
> I m just printing the received messages in the console.


That sounds strange. before consuming, there is only one "test" queue,
but when you begins to consume, there are new queues created under the
exchange, with the same queue content as "test". Have I described that
correctly? Are you sure you are not declaring the fanout exchange?

regards.

Ishwarya K

unread,
Oct 31, 2019, 6:00:25 AM10/31/19
to rabbitmq-users
Queue name      :: testQueue
Exchange name :: wsexchange
Routing key        :: test


Initially I have only one queue. After i run my application with my subscribe code, new queue with random name is getting created and subscribed. This new queue is bounded to 'wsexchange' with 'test' routing key.

Regards
Ishwarya

Wesley Peng

unread,
Oct 31, 2019, 6:02:57 AM10/31/19
to rabbitm...@googlegroups.com
Ishwarya K wrote:
> Queue name      :: testQueue
> Exchange name :: wsexchange
> Routing key        :: test
>
>
> Initially I have only one queue. After i run my application with my
> subscribe code, new queue with random name is getting created and
> subscribed. This new queue is bounded to 'wsexchange' with 'test'
> routing key.

well, i didn't see where you declared the queue name in consumer code.

regards.

Ishwarya K

unread,
Oct 31, 2019, 6:11:08 AM10/31/19
to rabbitmq-users
I am new to this. I am not sure how to subscribe to queue using stomp client. When i googled , i end up with below format. 

/exchange/{exchange_name}/{routing_key}


Above link also gives the same format. Can you please help me with right way to subscribe to an existing queue.


Regards
Ishwarya

Wesley Peng

unread,
Oct 31, 2019, 6:17:10 AM10/31/19
to rabbitm...@googlegroups.com
Ishwarya K wrote:
> I am new to this. I am not sure how to subscribe to queue using stomp
> client. When i googled , i end up with below format.
>
> /exchange/{exchange_name}/{routing_key}
>
> https://www.rabbitmq.com/stomp.html#d.ed
>
> Above link also gives the same format. Can you please help me with right
> way to subscribe to an existing queue.
>

Please follow my guide (I use ruby only).

#
# the producer program
#
$ cat producer.rb
require "bunny"

conn = Bunny.new
conn.start
ch = conn.create_channel
x = ch.direct("wsexchange")

1000.times do
data = rand.to_s
x.publish(data, :routing_key => 'test')
end


#
# the consumer program
#
$ cat consumer.rb
require "bunny"

conn = Bunny.new
conn.start

ch = conn.create_channel
x = ch.direct("wsexchange")
q = ch.queue("testQueue").bind(x, :routing_key => "test")

q.subscribe(:block => true) do |delivery_info, metadata, payload|
puts "Received #{payload}"
end


To test it, run producer program firstly, then run consumer program, we
will see output correctly.

Received 0.9846209815105557
Received 0.7340946810455584
Received 0.9055140842217664
Received 0.30372234393666
Received 0.7263295859033466
Received 0.9394455518373213
Received 0.9236682300440772
Received 0.22764352796122045
Received 0.9284674254665378
Received 0.812055013318445
Received 0.5145959032866338
Received 0.7068091947330086
Received 0.8134814516496319
Received 0.2189710182221163
Received 0.5363924946974395
Received 0.7105372851384832
Received 0.672852692655598
...


Regards.

Ishwarya K

unread,
Oct 31, 2019, 6:25:52 AM10/31/19
to rabbitmq-users
Thanks Wesley. Actually i m able consume from the queue, using my java code. But my requirement is to do it via websocket. Thats why i m trying to do it using STOMP. 


Regards
Ishwarya

Wesley Peng

unread,
Oct 31, 2019, 6:30:35 AM10/31/19
to rabbitm...@googlegroups.com
Ishwarya K wrote:
> Thanks Wesley. Actually i m able consume from the queue, using my java
> code. But my requirement is to do it via websocket. Thats why i m trying
> to do it using STOMP.
>

I see. If you didn't specify the queue name,the client will create a new
name by random. So as my code shows, you should specify the special
queue name when consuming.

Regards.

Ishwarya K

unread,
Oct 31, 2019, 6:37:13 AM10/31/19
to rabbitmq-users
Yea. But i m not sure where to define my queue name :(


Regards

Wesley Peng

unread,
Oct 31, 2019, 6:39:37 AM10/31/19
to rabbitm...@googlegroups.com
Ishwarya K wrote:
> Yea. But i m not sure where to define my queue name :(
>

I am not familiar with your language. So please check the library
documentation by yourself.

Regards.
Reply all
Reply to author
Forward
0 new messages