amqp-boilerplate 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/CHANGELOG +4 -0
- data/README.rdoc +19 -1
- data/lib/amqp/boilerplate/consumer.rb +25 -0
- data/lib/amqp/boilerplate/consumer_registry.rb +5 -0
- data/lib/amqp/boilerplate/logging.rb +4 -0
- data/lib/amqp/boilerplate/producer.rb +14 -1
- data/lib/amqp/boilerplate/version.rb +1 -1
- data/lib/amqp/boilerplate.rb +11 -1
- metadata +19 -19
data/.gitignore
CHANGED
data/CHANGELOG
CHANGED
data/README.rdoc
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
= amqp-boilerplate
|
2
2
|
|
3
3
|
amqp-boilerplate is a set of helper classes and modules to be used with the
|
4
|
-
Ruby amqp gem.
|
4
|
+
{https://github.com/ruby-amqp/amqp Ruby amqp gem}.
|
5
5
|
|
6
6
|
== Install
|
7
7
|
|
@@ -11,6 +11,24 @@ Ruby amqp gem.
|
|
11
11
|
|
12
12
|
See {AMQP::Boilerplate.configure} for configuration options.
|
13
13
|
|
14
|
+
=== Ruby on Rails
|
15
|
+
|
16
|
+
Add a initializer +amqp.rb+ to your config/initializer folder with the following code:
|
17
|
+
|
18
|
+
Rails.configuration.threadsafe!
|
19
|
+
|
20
|
+
AMQP::Boilerplate.configure do |config|
|
21
|
+
config.logger = ::Rails.logger
|
22
|
+
config.consumer_paths += %W( #{Rails.root}/app/consumers )
|
23
|
+
config.connection_options = { :host => "localhost", :port => 5672, :vhost => Rails.env }
|
24
|
+
end
|
25
|
+
|
26
|
+
# Require all files that are no longer auto-loaded when Rails is in thread-safe mode
|
27
|
+
Dir[File.expand_path(File.join(Rails.root,'lib','**','*.rb'))].each {|f| require f}
|
28
|
+
Dir[File.expand_path(File.join(Rails.root,'app','producers','**','*.rb'))].each {|f| require f}
|
29
|
+
|
30
|
+
AMQP::Boilerplate.boot
|
31
|
+
|
14
32
|
== Usage
|
15
33
|
|
16
34
|
amqp-boilerplate provides the AMQP::Boilerplate::Producer module for creating
|
@@ -1,5 +1,12 @@
|
|
1
1
|
module AMQP
|
2
2
|
module Boilerplate
|
3
|
+
# Inherit from this class to turn a class into a potential consumer that can
|
4
|
+
# handle messages delivered to them by AMQP broker.
|
5
|
+
#
|
6
|
+
# You should call the macro {.amqp_queue} method and implement {#handle_message}.
|
7
|
+
#
|
8
|
+
# To specify subscription options you can call the optional macro {.amqp_subscription} method.
|
9
|
+
#
|
3
10
|
# @example Basic consumer
|
4
11
|
# class MyConsumer < AMQP::Boilerplate::Consumer
|
5
12
|
# amqp_queue "hello.world"
|
@@ -8,6 +15,16 @@ module AMQP
|
|
8
15
|
# puts "Received message: #{payload}"
|
9
16
|
# end
|
10
17
|
# end
|
18
|
+
#
|
19
|
+
# @example Configuring subscription
|
20
|
+
# class MyConsumer < AMQP::Boilerplate::Consumer
|
21
|
+
# amqp_queue "queue.name.here", :durable => true
|
22
|
+
# amqp_subscription :ack => true
|
23
|
+
#
|
24
|
+
# def handle_message(payload, metadata)
|
25
|
+
# puts "Received message: #{payload}"
|
26
|
+
# end
|
27
|
+
# end
|
11
28
|
class Consumer
|
12
29
|
class << self
|
13
30
|
# Macro for selecting exchange to bind to
|
@@ -18,12 +35,20 @@ module AMQP
|
|
18
35
|
@exchange_name = name
|
19
36
|
end
|
20
37
|
|
38
|
+
# Macro that sets up the amqp_queue for a class.
|
39
|
+
#
|
40
|
+
# @param [String] name Queue name. If you want a server-named queue, you can omit the name.
|
41
|
+
# @param [Hash] options Options that will be passed as options to {http://rdoc.info/github/ruby-amqp/amqp/master/AMQP/Channel#queue-instance_method AMQP::Channel#queue}
|
42
|
+
# @return [void]
|
21
43
|
def amqp_queue(name=AMQ::Protocol::EMPTY_STRING, options={})
|
22
44
|
@queue_name = name
|
23
45
|
@queue_options = options
|
24
46
|
AMQP::Boilerplate.register_consumer(self)
|
25
47
|
end
|
26
48
|
|
49
|
+
# Macro that subscribes to asynchronous message delivery.
|
50
|
+
#
|
51
|
+
# @param [Hash] options Options that will be passed as options to {http://rdoc.info/github/ruby-amqp/amqp/master/AMQP/Queue#subscribe-instance_method AMQP::Queue#subscribe}
|
27
52
|
def amqp_subscription(options={})
|
28
53
|
@subscription_options = options
|
29
54
|
end
|
@@ -3,6 +3,11 @@ module AMQP
|
|
3
3
|
module ConsumerRegistry
|
4
4
|
attr_writer :consumer_paths
|
5
5
|
|
6
|
+
# Returns an array of paths which files are loaded when {AMQP::Boilerplate.boot} is called.
|
7
|
+
# You should define the consumer_paths when you configure +AMQP::Boilerplate+ and assign
|
8
|
+
# an array of paths pointing to the folder where your consumer files are located, to it.
|
9
|
+
#
|
10
|
+
# @see AMQP::Boilerplate.configure
|
6
11
|
def consumer_paths
|
7
12
|
@consumer_paths ||= []
|
8
13
|
end
|
@@ -5,6 +5,10 @@ module AMQP
|
|
5
5
|
module Logging
|
6
6
|
attr_writer :logger
|
7
7
|
|
8
|
+
# Returns the logger used to write logging output to.
|
9
|
+
# You can define the logger when you configure +AMQP::Boilerplate+ if you want to use a different logger than the default Ruby Logger.
|
10
|
+
#
|
11
|
+
# @see AMQP::Boilerplate.configure
|
8
12
|
def logger
|
9
13
|
@logger ||= ::Logger.new(STDOUT)
|
10
14
|
end
|
@@ -3,6 +3,11 @@ module AMQP
|
|
3
3
|
# Use this module to turn a class into a potential producer that can
|
4
4
|
# deliver messages to an AMQP exchange.
|
5
5
|
#
|
6
|
+
# You turn your class into a producer by extending the module
|
7
|
+
# and call the required macros {#amqp} and {#amqp_message} methods.
|
8
|
+
#
|
9
|
+
# To specify exchange options you can call the optional macro {#amqp_exchange} method.
|
10
|
+
#
|
6
11
|
# @example Getting started
|
7
12
|
# class MyProducer
|
8
13
|
# extend AMQP::Boilerplate::Producer
|
@@ -30,7 +35,7 @@ module AMQP
|
|
30
35
|
module Producer
|
31
36
|
# Macro that sets up amqp for a class.
|
32
37
|
#
|
33
|
-
# @param [Hash] opts Options that will be passed to
|
38
|
+
# @param [Hash] opts Options that will be passed as options to {http://rdoc.info/github/ruby-amqp/amqp/master/AMQP/Exchange#publish-instance_method AMQP::Exchange#publish}
|
34
39
|
# @return [void]
|
35
40
|
def amqp(opts={})
|
36
41
|
send :include, InstanceMethods
|
@@ -40,6 +45,8 @@ module AMQP
|
|
40
45
|
# Configuration for the exchange to be used
|
41
46
|
#
|
42
47
|
# @param [Symbol] type Exchange type
|
48
|
+
#
|
49
|
+
# There are 4 supported exchange types: direct, fanout, topic and headers. Exchange type determines how exchange processes and routes messages.
|
43
50
|
# @param [String] name Exchange name
|
44
51
|
# @param [Hash] opts a customizable set of options
|
45
52
|
# @see AMQP::Exchange#initialize
|
@@ -55,6 +62,12 @@ module AMQP
|
|
55
62
|
#
|
56
63
|
# @param [Symbol] method_name Name of method that generates message
|
57
64
|
# @return [void]
|
65
|
+
# @example
|
66
|
+
# amqp_message :message
|
67
|
+
#
|
68
|
+
# def message
|
69
|
+
# "Look! I am a string that will be posted to the exchange."
|
70
|
+
# end
|
58
71
|
def amqp_message(method_name)
|
59
72
|
@amqp_boilerplate_message = method_name
|
60
73
|
end
|
data/lib/amqp/boilerplate.rb
CHANGED
@@ -41,7 +41,14 @@ module AMQP
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
-
#
|
44
|
+
# Configures AMQP::Boilerplate and yields AMQP::Boilerplate object to the block
|
45
|
+
#
|
46
|
+
# @example
|
47
|
+
# AMQP::Boilerplate.configure do |config|
|
48
|
+
# config.logger = ::Rails.logger
|
49
|
+
# config.consumer_paths += %W( #{Rails.root}/app/consumers )
|
50
|
+
# config.connection_options = { :host => "localhost", :port => 5672, :vhost => Rails.env }
|
51
|
+
# end
|
45
52
|
def self.configure
|
46
53
|
yield self if block_given?
|
47
54
|
end
|
@@ -50,6 +57,9 @@ module AMQP
|
|
50
57
|
@connection_options
|
51
58
|
end
|
52
59
|
|
60
|
+
# AMQP connection options (:host, :port, :username, :vhost, :password) that
|
61
|
+
# will be passed as connection_options to {http://rdoc.info/github/ruby-amqp/amqp/master/AMQP#connect-class_method AMQP#start}
|
62
|
+
# when starting an EventMachine event loop.
|
53
63
|
def self.connection_options=(options)
|
54
64
|
@connection_options = options
|
55
65
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: amqp-boilerplate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Patrick Baselier
|
@@ -21,8 +21,8 @@ default_executable:
|
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
23
23
|
name: rake
|
24
|
-
|
25
|
-
|
24
|
+
prerelease: false
|
25
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
26
26
|
none: false
|
27
27
|
requirements:
|
28
28
|
- - ~>
|
@@ -32,12 +32,12 @@ dependencies:
|
|
32
32
|
- 0
|
33
33
|
- 9
|
34
34
|
version: "0.9"
|
35
|
-
|
36
|
-
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id001
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: rspec
|
39
|
-
|
40
|
-
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
42
42
|
requirements:
|
43
43
|
- - ~>
|
@@ -47,12 +47,12 @@ dependencies:
|
|
47
47
|
- 2
|
48
48
|
- 6
|
49
49
|
version: "2.6"
|
50
|
-
|
51
|
-
|
50
|
+
type: :development
|
51
|
+
version_requirements: *id002
|
52
52
|
- !ruby/object:Gem::Dependency
|
53
53
|
name: yard
|
54
|
-
|
55
|
-
|
54
|
+
prerelease: false
|
55
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
56
56
|
none: false
|
57
57
|
requirements:
|
58
58
|
- - ~>
|
@@ -62,12 +62,12 @@ dependencies:
|
|
62
62
|
- 0
|
63
63
|
- 7
|
64
64
|
version: "0.7"
|
65
|
-
|
66
|
-
|
65
|
+
type: :development
|
66
|
+
version_requirements: *id003
|
67
67
|
- !ruby/object:Gem::Dependency
|
68
68
|
name: amqp
|
69
|
-
|
70
|
-
|
69
|
+
prerelease: false
|
70
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
71
71
|
none: false
|
72
72
|
requirements:
|
73
73
|
- - ~>
|
@@ -77,8 +77,8 @@ dependencies:
|
|
77
77
|
- 0
|
78
78
|
- 8
|
79
79
|
version: "0.8"
|
80
|
-
|
81
|
-
|
80
|
+
type: :runtime
|
81
|
+
version_requirements: *id004
|
82
82
|
description: Collection of modules that aid in setting up AMQP producers and consumers.
|
83
83
|
email:
|
84
84
|
- patrick@kabisa.nl
|