-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port [Python] example for Chapter 1 to Ruby
- Loading branch information
1 parent
2798673
commit 368d2a1
Showing
4 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
*~ | ||
*# | ||
*.class | ||
*.rbc | ||
Gemfile.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
source :rubygems | ||
|
||
gem "amqp", "~> 0.8.0.RC12" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
if defined?(Bundler); Bundler.setup; else; require "rubygems"; end | ||
|
||
require "amqp" | ||
|
||
EventMachine.run do | ||
AMQP.connect(:host => "localhost", :username => "guest", :password => "guest") do |connection| | ||
puts "Connected. Waiting for messages... Hit Control + C to stop me." | ||
|
||
channel = AMQP::Channel.new(connection) | ||
exchange = channel.direct("hello-exchange", :durable => true, :auto_delete => false) | ||
channel.queue("hello-queue", :durable => true, :auto_delete => false).bind(exchange, :routing_key => "hola").subscribe do |header, body| | ||
puts "Received #{body}" | ||
|
||
connection.close { EventMachine.stop } | ||
end | ||
|
||
# stop on Control + c or after 1 second | ||
stop = Proc.new { connection.close { EventMachine.stop } } | ||
Signal.trap("INT", &stop) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
if defined?(Bundler); Bundler.setup; else; require "rubygems"; end | ||
|
||
require "amqp" | ||
|
||
EventMachine.run do | ||
AMQP.connect(:host => "localhost", :username => "guest", :password => "guest") do |connection| | ||
puts "Connected. Hit Control + C to stop me." | ||
|
||
channel = AMQP::Channel.new(connection) | ||
channel.direct("hello-exchange", :durable => true, :auto_delete => false). | ||
publish(ARGV[0], :routing_key => "hola") | ||
|
||
# stop on Control + c or after 1 second | ||
stop = Proc.new { connection.close { EventMachine.stop } } | ||
Signal.trap("INT", &stop) | ||
EventMachine.add_timer(1, &stop) | ||
end | ||
end |