Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Messages queues don't need to be scary.

Messages queues don't need to be scary.

An introduction tutorial to AMQP with RabbitMQ and Ruby.

Glen Mailer

October 14, 2013

More Decks by Glen Mailer

Other Decks in Technology


  1. Producer c = create_channel q = c.queue("task") x = c.default_exchange

    x.publish( "task", "payload" ) Consumer c = create_channel q = c.queue("task") q.subscribe(worker) worker = fn(*message) { // do stuff }
  2. Acknowledging Messages q = c.queue("task") q.subscribe(worker, ack = TRUE) worker

    = fn(info, metadata, body) { // do work c.acknowledge(info.delivery_tag) }
  3. Publishing Options Mandatory Will error if not queued Immediate Will

    error if no consumer available Confirm Server acknowledges receipt
  4. Queue Declare Options Passive Don't create, get reference to existing

    queue Durable Queue still exists after a broker restart
  5. Binding a Queue x = c.exchange("activity”) q = c.queue("alert") q.bind(x,

    "balance.*") q.bind(x, "transfer.out") x.publish("balance.low") x.publish("transfer.in") x.publish("transfer.out")
  6. Queue Declare Options Exclusive Only one consumer on this queue

    at any time Auto Delete Queue is deleted after consumer disconnects
  7. Correlation ID x.publish("request1", :headers => { :replyTo => "abcdef", :correlationID

    => "request1" }) x.publish("request2", :headers => { :replyTo => "abcdef", :correlationID => "request2" })
  8. declare_options = {:no_declare => true}
 q = ch.queue(name, options)

    options = {:block => true, :ack => true}
 q.subscribe(options) do |info, meta, body|
 # do stuff