Class: ElmerFudd::DirectHandler
- Inherits:
-
Object
- Object
- ElmerFudd::DirectHandler
- Includes:
- Filter
- Defined in:
- lib/ElmerFudd/direct_handler.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#call_reply_content_type ⇒ Object
Returns the value of attribute call_reply_content_type.
-
#route ⇒ Object
readonly
Returns the value of attribute route.
Instance Method Summary collapse
- #call(env, message) ⇒ Object
- #ensure_that_queue_exists(env) ⇒ Object
- #exchange(env) ⇒ Object
-
#initialize(route, callback, filters, options) ⇒ DirectHandler
constructor
A new instance of DirectHandler.
- #queue(env) ⇒ Object
Methods included from Filter
Constructor Details
#initialize(route, callback, filters, options) ⇒ DirectHandler
Returns a new instance of DirectHandler.
7 8 9 10 11 12 13 14 |
# File 'lib/ElmerFudd/direct_handler.rb', line 7 def initialize(route, callback, filters, ) @route = route @callback = callback @filters = filters @durable = .fetch(:durable) @call_reply_content_type = ElmerFudd::DEFAULT_CONTENT_TYPE initialize_filters end |
Instance Attribute Details
#call_reply_content_type ⇒ Object
Returns the value of attribute call_reply_content_type.
5 6 7 |
# File 'lib/ElmerFudd/direct_handler.rb', line 5 def call_reply_content_type @call_reply_content_type end |
#route ⇒ Object (readonly)
Returns the value of attribute route.
4 5 6 |
# File 'lib/ElmerFudd/direct_handler.rb', line 4 def route @route end |
Instance Method Details
#call(env, message) ⇒ Object
37 38 39 40 |
# File 'lib/ElmerFudd/direct_handler.rb', line 37 def call(env, ) env.logger.debug "ElmerFudd #{self.class.name}.call (#{object_id}) queue_name: #{@route.queue_name}, exchange_name: #{@route.exchange_name}, filters: #{filters_names}, message: #{.payload}" call_next(env, , @filters + [@callback]) end |
#ensure_that_queue_exists(env) ⇒ Object
28 29 30 |
# File 'lib/ElmerFudd/direct_handler.rb', line 28 def ensure_that_queue_exists(env) env.channel.queue_declare(@route.queue_name, durable: @durable, exclusive: is_exclusive_queue) end |
#exchange(env) ⇒ Object
32 33 34 35 |
# File 'lib/ElmerFudd/direct_handler.rb', line 32 def exchange(env) env.logger.debug "ElmerFudd Handler.exchange queue_name: #{@route.queue_name}, exchange_name: #{@route.exchange_name}, filters: #{filters_names}" env.channel.direct(@route.exchange_name) end |
#queue(env) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/ElmerFudd/direct_handler.rb', line 16 def queue(env) ensure_that_queue_exists(env) env.channel.queue(@route.queue_name, durable: @durable, exclusive: is_exclusive_queue).tap do |queue| unless @route.exchange_name == "" Array(@route.routing_keys).each do |routing_key| queue.bind(exchange(env), routing_key: routing_key) end end @route.queue_name = queue.name end end |