Skip to content

Instantly share code, notes, and snippets.

@kares
Forked from andsel/sender.rb
Last active June 2, 2021 10:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kares/c9e303c0d34c819bc675f463095e21f5 to your computer and use it in GitHub Desktop.
Save kares/c9e303c0d34c819bc675f463095e21f5 to your computer and use it in GitHub Desktop.
Simple RabbitMQ sender
input {
rabbitmq {
codec => plain
host => "localhost"
key => "#"
exchange => "sysmsg" # string (optional)
queue => 'dur-no-policy-4'
durable => true
threads => 1
prefetch_count => 50
}
}
output {
stdout { codec => rubydebug }
}
require 'march_hare'
conn = MarchHare.connect(:host => "localhost")
ch = conn.create_channel
exchange = ch.direct("sysmsg", :durable => true)
#exchange = ch.direct("sysmsg")
puts "exchange: #{exchange}"
#queue = ch.queue("ls-dur-1", :auto_delete => false, :durable => true).bind(exchange, :routing_key => "temp")
#queue = ch.queue("ls-dur-1", :durable => true).bind(exchange, :routing_key => "#")
#queue = ch.queue("non-dur-2", :durable => false).bind(exchange, :routing_key => "#")
#queue = ch.queue("non-dur-3", :durable => false)
#queue = ch.queue("ls-dur-2", :durable => true)
#queue = ch.queue("ls-dur-3", :durable => true).bind(exchange, :routing_key => "#")
queue = ch.queue("dur-no-policy-4", :durable => true).bind(exchange, :routing_key => "#")
puts "queue: #{queue}"
begin
i = 0
while(true)
print "."
#exchange.publish("X#{(i += 1)}", :routing_key => "#")
queue.publish("Y#{(i += 1)}", :routing_key => "#")
sleep 0.25
(sleep 3.5; puts "\n") if i > 0 && i % 100 == 0
end
ensure
# we do not want to delete (durable) queue/exchange on the server
# 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