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.