Class: EventBus::Broker::Rabbit::Topic

Inherits:
Object
  • Object
show all
Defined in:
lib/event_bus/broker/rabbit/topic.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection) ⇒ Topic

Returns a new instance of Topic.



4
5
6
# File 'lib/event_bus/broker/rabbit/topic.rb', line 4

def initialize(connection)
  @channel = connection
end

Class Method Details

.produce(connection, event) ⇒ Object



16
17
18
# File 'lib/event_bus/broker/rabbit/topic.rb', line 16

def self.produce(connection, event)
  new(connection).produce(event)
end

.topic(connection) ⇒ Object



8
9
10
# File 'lib/event_bus/broker/rabbit/topic.rb', line 8

def self.topic(connection)
  new(connection).topic
end

Instance Method Details

#produce(event) ⇒ Object



20
21
22
23
# File 'lib/event_bus/broker/rabbit/topic.rb', line 20

def produce(event)
  topic.publish(event.payload, routing_key: event.name,
                content_type: 'application/json')
end

#topicObject



12
13
14
# File 'lib/event_bus/broker/rabbit/topic.rb', line 12

def topic
  @topic ||= channel.topic(EventBus::Config::TOPIC, topic_options)
end