Class: Rabbitek::Publisher

Inherits:
Object
  • Object
show all
Defined in:
lib/rabbitek/client/publisher.rb

Overview

Handles publishing message to RabbitMQ

Instance Method Summary collapse

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

#closeObject



19
20
21
# File 'lib/rabbitek/client/publisher.rb', line 19

def close
  @channel.close
end

#exchangeObject



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