Skip to content

Instantly share code, notes, and snippets.

@andsel
Last active June 2, 2021 10:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save andsel/1d3a734337d29023680ac9a5cd349d18 to your computer and use it in GitHub Desktop.
Save andsel/1d3a734337d29023680ac9a5cd349d18 to your computer and use it in GitHub Desktop.
Simple RabbitMQ sender
#run dockerized RabbitMQ
# docker run -v rabbitmq-data:/var/lib/rabbitmq --hostname my-rabbit --name rabbit_dev -p 15672:15672 -p 5672:5672 rabbitmq:3-management
# navigate to http://localhost:15672/#/queues
# login guest:guest
require 'march_hare'
conn = MarchHare.connect(:host => "localhost")
ch = conn.create_channel
exchange = ch.direct("sysmsg", :durable => true)
queue = ch.queue("iot_queue", :auto_delete => false, :durable => true).bind(exchange, :routing_key => "temp")
puts "Queue created"
begin
while(true)
puts "."
exchange.publish("27C", :routing_key => "temp")
sleep 0.5
end
ensure
puts "cleanup"
exchange.delete
queue.delete
ch.close
conn.close
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment