Permalink
Browse files

Updated examples.

Simple now has examples of both default adapters (logically named.)
Auth'd only uses the AMQP adapter by default, but change "amqp" to "bunny" on line 3 in sender.rb or receiver.rb and it'll use Bunny adapter instead.
  • Loading branch information...
1 parent 538fd1f commit 3f44d889a504b3a6c72eb0218fdd46a6c31fc7ee @caius caius committed Jun 12, 2009
@@ -1,5 +1,7 @@
require "rubygems"
require File.expand_path(File.dirname(__FILE__) + "/../../lib/warren")
+require File.expand_path(File.dirname(__FILE__) + "/../../lib/warren/adapters/amqp_adapter")
+require File.expand_path(File.dirname(__FILE__) + "/../../lib/warren/filters/shared_secret")
Signal.trap("INT") { AMQP.stop { EM.stop } }
Signal.trap("TERM") { AMQP.stop { EM.stop } }
@@ -9,7 +11,7 @@
puts "Listening to the #{q} queue."
# Setup the connection directly this time
-Warren::Queue.connection = {:user => "caius", :pass => "caius", :vhost => "/"}
+Warren::Queue.connection = {"development" => {:user => "caius", :pass => "caius", :vhost => "/"}}
# Set the secret key
require File.expand_path(File.dirname(__FILE__) + "/secret")
@@ -1,16 +1,18 @@
require "rubygems"
require File.expand_path(File.dirname(__FILE__) + "/../../lib/warren")
+require File.expand_path(File.dirname(__FILE__) + "/../../lib/warren/adapters/amqp_adapter")
+require File.expand_path(File.dirname(__FILE__) + "/../../lib/warren/filters/shared_secret")
Signal.trap("INT") { exit! }
Signal.trap("TERM") { exit! }
# Setup our own connection before generating the queue object
-conn = Warren::Connection.new(
+conn = Warren::Connection.new("development" => {
:user => "caius",
:pass => "caius",
:vhost => "/",
:default_queue => "main"
-)
+})
# Set the connection for the queue
Warren::Queue.connection = conn
# Generate some data to send
@@ -0,0 +1,18 @@
+require "rubygems"
+require File.expand_path(File.dirname(__FILE__) + "/../../lib/warren")
+# Next line is the only one you need to change to use a different adapter
+require File.expand_path(File.dirname(__FILE__) + "/../../lib/warren/adapters/amqp_adapter")
+
+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."
+
+Warren::Queue.connection = {"development" => {:user => "caius", :pass => "caius", :vhost => "/"}}
+
+# And attach a block for new messages to fire
+Warren::Queue.subscribe(q) do |msg|
+ p [Time.now, msg]
+end
@@ -1,16 +1,18 @@
require "rubygems"
-require File.expand_path(File.dirname(__FILE__) + "/../lib/warren")
+require File.expand_path(File.dirname(__FILE__) + "/../../lib/warren")
+# Next line is the only one you need to change to use a different adapter
+require File.expand_path(File.dirname(__FILE__) + "/../../lib/warren/adapters/amqp_adapter")
Signal.trap("INT") { exit! }
Signal.trap("TERM") { exit! }
# Setup our own connection before generating the queue object
-conn = Warren::Connection.new(
+conn = Warren::Connection.new("development" => {
:user => "caius",
:pass => "caius",
:vhost => "/",
:default_queue => "main"
-)
+})
# Set the connection for the queue
Warren::Queue.connection = conn
# Generate some data to send
@@ -26,8 +28,9 @@
}
]
}
+
# 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" }
+# p Warren::Queue.publish(:default, data) { "foo" }
@@ -0,0 +1,18 @@
+require "rubygems"
+require File.expand_path(File.dirname(__FILE__) + "/../../lib/warren")
+# Next line is the only one you need to change to use a different adapter
+require File.expand_path(File.dirname(__FILE__) + "/../../lib/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."
+
+Warren::Queue.connection = {"development" => {:user => "caius", :pass => "caius", :vhost => "/"}}
+
+# And attach a block for new messages to fire
+Warren::Queue.subscribe(q) do |msg|
+ p [Time.now, msg]
+end
@@ -0,0 +1,36 @@
+require "rubygems"
+require File.expand_path(File.dirname(__FILE__) + "/../../lib/warren")
+# Next line is the only one you need to change to use a different adapter
+require File.expand_path(File.dirname(__FILE__) + "/../../lib/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 => "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"
+ }
+ ]
+}
+
+# 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" }
@@ -1,17 +0,0 @@
-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 => "/"}
-
-# And attach a block for new messages to fire
-Warren::Queue.subscribe(q) do |msg|
- p [Time.now, msg]
-end

0 comments on commit 3f44d88

Please sign in to comment.