Class: Rabbitek::Publisher
- Inherits:
-
Object
- Object
- Rabbitek::Publisher
- Defined in:
- lib/rabbitek/client/publisher.rb
Overview
Handles publishing message to RabbitMQ
Instance Method Summary collapse
- #close ⇒ Object
- #exchange ⇒ Object
-
#initialize(exchange_name, exchange_type: 'direct', channel: nil) ⇒ Publisher
constructor
A new instance of Publisher.
- #publish(payload, params = {}) ⇒ Object
Constructor Details
#initialize(exchange_name, exchange_type: 'direct', channel: nil) ⇒ Publisher
Returns a new instance of Publisher.
7 8 9 10 11 |
# File 'lib/rabbitek/client/publisher.rb', line 7 def initialize(exchange_name, exchange_type: 'direct', channel: nil) @channel = channel || Rabbitek.create_channel @exchange_name = exchange_name @exchange_type = exchange_type end |
Instance Method Details
#close ⇒ Object
19 20 21 |
# File 'lib/rabbitek/client/publisher.rb', line 19 def close @channel.close end |
#exchange ⇒ Object
23 24 25 |
# File 'lib/rabbitek/client/publisher.rb', line 23 def exchange @exchange ||= Utils::Common.exchange(@channel, @exchange_type, @exchange_name) end |
#publish(payload, params = {}) ⇒ Object
13 14 15 16 17 |
# File 'lib/rabbitek/client/publisher.rb', line 13 def publish(payload, params = {}) Utils::HookWalker.new(Rabbitek.config.client_hooks).call!(payload, params) do |parsed_payload, parsed_params| exchange.publish(Utils::Oj.dump(parsed_payload), parsed_params) end end |