Regarding Carrot Gems for ruby

97 views Asked by At

I am using carrot gem for message publishing in ruby and my sample code is as follows :

Code :

require 'carrot'

q = Carrot.queue('testqueue', :durable => true)

q.publish("sample data")

Please can someone tell me how to publish the same data using a routing key ?

1

There are 1 answers

0
phoet On

With my limited amount of knowledge about AMQP but my extraordinary abilities in using Google i found out that for using routing keys:

We will use a direct exchange instead. The routing algorithm behind a direct exchange is simple - a message goes to the queues whose binding key exactly matches the routing key of the message.

And that this is how you use carrot with the direct exchange:

require 'carrot'

c = Carrot.new
q = c.queue('queue_name', {
  host: 'example.com',
  user: 'username',
  pass: 'passwd',
  vhost: '/',
  auto_delete: true
})
c.direct("name.exchange", { :durable => true })