Class: Untied::Publisher::BaseProducer

Inherits:
Object
  • Object
show all
Defined in:
lib/untied-publisher/base_producer.rb

Overview

Generic class to provide message publishing.

Instance Attribute Summary collapse

Instance Method Summary collapse

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={})
  extract_options!(opts)
end

Instance Attribute Details

#deliver_messagesObject (readonly)

Returns the value of attribute deliver_messages.



7
8
9
# File 'lib/untied-publisher/base_producer.rb', line 7

def deliver_messages
  @deliver_messages
end

#routing_keyObject (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_nameObject (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 deliver_messages
    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