Commit e5d5b6e

mo khan <mo@mokhan.ca>
2014-10-10 16:17:47
add example of worker program.
1 parent 591ef36
Changed files (2)
lib/example2/receive.rb
@@ -0,0 +1,18 @@
+#!/env ruby
+# encoding: utf-8
+
+require "bunny"
+
+connection = Bunny.new
+connection.start
+
+channel = connection.create_channel
+queue = channel.queue("hello")
+
+puts " [*] Waiting for messages in #{queue.name}. To exit press CTRL+C"
+queue.subscribe(ack: true, block: true) do |delivery_info, properties, body|
+  puts " [x] Received #{body}"
+  sleep body.count(".").to_i
+  puts " [x] Done"
+  channel.ack(delivery_info.delivery_tag)
+end
lib/example2/send.rb
@@ -0,0 +1,15 @@
+#!/env ruby
+# encoding: utf-8
+
+require "bunny"
+
+connection = Bunny.new
+connection.start
+
+channel = connection.create_channel
+queue = channel.queue("hello")
+
+message  = ARGV.empty? ? "Hello World!" : ARGV.join(" ")
+queue.publish(message, persistent: true)
+puts " [x] Sent #{message}"
+connection.close