Skip to content

Instantly share code, notes, and snippets.

@caius
Created December 12, 2017 12:50
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 caius/0d8f03098b990cd661f22b0dae3206be to your computer and use it in GitHub Desktop.
Save caius/0d8f03098b990cd661f22b0dae3206be to your computer and use it in GitHub Desktop.
require_relative "./shared"
seen_ids = []
$q.subscribe(:block => true, :manual_ack => true) do |delivery_info, metadata, payload|
data = JSON.parse(payload)
p "Got #{data["id"]} (#{data["nack"]})"
if seen_ids.include?(data["id"])
raise "Dup! Already seen this message"
end
seen_ids << data["id"]
if data["nack"]
$channel.nack(delivery_info.delivery_tag, false, true)
else
$channel.ack(delivery_info.delivery_tag)
end
end
require_relative "./shared"
1.upto(Float::INFINITY) do |i|
payload = {
:id => i,
:nack => (i == 2)
}
$x.publish(payload.to_json, :routing_key => $q.name)
end
$conn.close
require "bunny"
require "json"
$conn = Bunny.new
$conn.start
$channel = $conn.create_channel
$q = $channel.queue("foo", :auto_delete => false)
$x = $channel.fanout("one")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment