Class: Untied::Publisher::BaseProducer
- Inherits:
-
Object
- Object
- Untied::Publisher::BaseProducer
- Defined in:
- lib/untied-publisher/base_producer.rb
Overview
Generic class to provide message publishing.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#deliver_messages ⇒ Object
readonly
Returns the value of attribute deliver_messages.
-
#routing_key ⇒ Object
readonly
Returns the value of attribute routing_key.
-
#service_name ⇒ Object
readonly
Returns the value of attribute service_name.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ BaseProducer
constructor
A new instance of BaseProducer.
-
#publish(event) ⇒ Object
Publish the given event.
Constructor Details
#initialize(opts = {}) ⇒ BaseProducer
Returns a new instance of BaseProducer.
9 10 11 |
# File 'lib/untied-publisher/base_producer.rb', line 9 def initialize(opts={}) (opts) end |
Instance Attribute Details
#deliver_messages ⇒ Object (readonly)
Returns the value of attribute deliver_messages.
7 8 9 |
# File 'lib/untied-publisher/base_producer.rb', line 7 def @deliver_messages end |
#routing_key ⇒ Object (readonly)
Returns the value of attribute routing_key.
7 8 9 |
# File 'lib/untied-publisher/base_producer.rb', line 7 def routing_key @routing_key end |
#service_name ⇒ Object (readonly)
Returns the value of attribute service_name.
7 8 9 |
# File 'lib/untied-publisher/base_producer.rb', line 7 def service_name @service_name end |
Instance Method Details
#publish(event) ⇒ Object
Publish the given event.
event: object which is going to be serialized and sent through the
wire. It should respond to #to_json.
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/untied-publisher/base_producer.rb', line 16 def publish(event) if safe_publish(event) say "Publishing event with routing key #{routing_key}: #{event.to_json}" else say "Event produced but not delivered. If you want to deliver it " + \ "try to set Untied::Publisher.config.deliver_messages to true. " + \ "Event: #{event.to_json}" end end |