Skip to content

Commit

Permalink
Updating examples
Browse files Browse the repository at this point in the history
  • Loading branch information
caius committed Mar 13, 2009
1 parent c6d3eec commit ea3c40d
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 1 deletion.
23 changes: 23 additions & 0 deletions examples/authed/receiver.rb
@@ -0,0 +1,23 @@
require "rubygems"
require File.expand_path(File.dirname(__FILE__) + "/../../lib/warren")

Signal.trap("INT") { AMQP.stop { EM.stop } }
Signal.trap("TERM") { AMQP.stop { EM.stop } }

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

# Setup the connection directly this time
Warren::Queue.connection = {:user => "caius", :pass => "caius", :vhost => "/"}

# Set the secret key
require File.expand_path(File.dirname(__FILE__) + "/secret")
Warren::MessageFilter::SharedSecret.key = SUPER_SECRET_KEY
# And add the filter
Warren::MessageFilter << Warren::MessageFilter::SharedSecret

# And attach a block for new messages to fire
Warren::Queue.subscribe(q) do |msg|
p [Time.now, msg]
end
1 change: 1 addition & 0 deletions examples/authed/secret.rb
@@ -0,0 +1 @@
SUPER_SECRET_KEY = "This is my super secret string"
38 changes: 38 additions & 0 deletions examples/authed/sender.rb
@@ -0,0 +1,38 @@
require "rubygems"
require File.expand_path(File.dirname(__FILE__) + "/../../lib/warren")

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

# Setup our own connection before generating the queue object
conn = Warren::Connection.new(
:user => "caius",
:pass => "caius",
:vhost => "/",
:default_queue => "main"
)
# 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"
}
]
}

# Set the secret key
require File.expand_path(File.dirname(__FILE__) + "/secret")
Warren::MessageFilter::SharedSecret.key = SUPER_SECRET_KEY

# And add the filter
Warren::MessageFilter << Warren::MessageFilter::SharedSecret

# Push a message onto the queue
p Warren::Queue.publish(:default, data )
2 changes: 1 addition & 1 deletion examples/mass_sender.rb → examples/simple/mass_sender.rb
Expand Up @@ -14,7 +14,7 @@
# Set the connection for the queue
Warren::Queue.connection = conn

100.times do | i |
1000.times do | i |
puts i
sleep 0.1
Warren::Queue.publish(:default, "Message no #{i}") { puts "sent ##{i}" }
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit ea3c40d

Please sign in to comment.