Skip to content

Commit

Permalink
Added warren/bunny simple examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Alberto Perdomo committed Dec 18, 2009
1 parent ec40265 commit 775270f
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
26 changes: 26 additions & 0 deletions warren/warren_bunny_receiver.rb
@@ -0,0 +1,26 @@
require "rubygems"
require "warren"
require "warren/adapters/bunny_adapter"

Signal.trap("INT") { exit! }
Signal.trap("TERM") { exit! }

# Listen to the main queue
q = "main"
puts "Listening to the #{q} queue."

# Setup our own connection before generating the queue object
conn = Warren::Connection.new("development" => {
:user => "guest",
:pass => "guest",
:vhost => "/",
:default_queue => "main",
:logging => false
})
# Set the connection for the queue
Warren::Queue.connection = conn

# And attach a block for new messages to fire
Warren::Queue.subscribe(q) do |msg|
p [Time.now, msg]
end
36 changes: 36 additions & 0 deletions warren/warren_bunny_sender.rb
@@ -0,0 +1,36 @@
require "rubygems"
require "warren"
require "warren/adapters/bunny_adapter"

Signal.trap("INT") { exit! }
Signal.trap("TERM") { exit! }

# Setup our own connection before generating the queue object
conn = Warren::Connection.new("development" => {
:user => "guest",
:pass => "guest",
:vhost => "/",
:default_queue => "main",
:logging => false
})
# Set the connection for the queue
Warren::Queue.connection = conn
# Generate some data to send
data = {
:people => [
:fred => {
:age => 25,
:location => "Leeds"
},
:george => {
:age => 32,
:location => "London"
}
]
}

# Push a message onto the queue
p Warren::Queue.publish(:default, data )

# And then push a message onto the queue, returning "foo"
#p Warren::Queue.publish(:default, data) { "foo" }

0 comments on commit 775270f

Please sign in to comment.