Skip to content

Instantly share code, notes, and snippets.

@igkuz
Created March 12, 2019 16:06
Show Gist options
  • Save igkuz/4040cf79168f62761a1b6a68ad6250d6 to your computer and use it in GitHub Desktop.
Save igkuz/4040cf79168f62761a1b6a68ad6250d6 to your computer and use it in GitHub Desktop.
Starting point to create RabbitMQ exchanges and queues with ruby
#!/usr/bin/env ruby
# encoding utf-8
require 'bunny'
STDOUT.sync = true
conn = Bunny.new(host: 'rmq', user: 'guest', pass: 'guest')
conn.start
ch = conn.create_channel
x = ch.direct('work.exchange')
dlx = ch.direct('retry.exchange')
target_queue = ch.queue('work.queue', arguments: {
:'x-dead-letter-exchange' => 'retry.exchange'
}).bind(x, routing_key: 'work.queue')
retry_queue = ch.queue('retry.queue', arguments: {
:'x-dead-letter-exchange' => 'work.exchange',
:'x-message-ttl' => 60000
}).bind(dlx, routing_key: 'work.queue')
conn.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment