Class: Artsy::EventService::Publisher
- Inherits:
-
Object
- Object
- Artsy::EventService::Publisher
show all
- Includes:
- RabbitMQConnection
- Defined in:
- lib/artsy-eventservice/artsy/event_service/publisher.rb
Class Method Summary
collapse
Instance Method Summary
collapse
#bunny_params, #config, #connect_to_rabbit, #create_conn, #no_tls_params, #rabbitmq_url, #tls_params
Class Method Details
.config ⇒ Object
26
27
28
|
# File 'lib/artsy-eventservice/artsy/event_service/publisher.rb', line 26
def self.config
Artsy::EventService.config
end
|
.publish(topic:, event:, routing_key: nil) ⇒ Object
7
8
9
|
# File 'lib/artsy-eventservice/artsy/event_service/publisher.rb', line 7
def self.publish(topic:, event:, routing_key: nil)
new.post_event(topic: topic, event: event, routing_key: routing_key)
end
|
Instance Method Details
#post_event(topic:, event:, routing_key: nil) ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/artsy-eventservice/artsy/event_service/publisher.rb', line 11
def post_event(topic:, event:, routing_key: nil)
raise 'Event missing topic or verb.' if event.verb.to_s.empty? || topic.to_s.empty?
connect_to_rabbit do |conn|
channel = conn.create_channel
exchange = channel.topic(topic, durable: true)
exchange.publish(
event.json,
routing_key: routing_key || event.verb,
persistent: true,
content_type: 'application/json',
app_id: config.app_name
)
end
end
|