Class: Jobi::Clients::Rabbitmq

Inherits:
Object
  • Object
show all
Defined in:
lib/jobi/clients/rabbitmq.rb

Constant Summary collapse

QUEUE_OPTIONS =
{
  durable: :durable
}.freeze
MESSAGE_OPTIONS =
{
  persist: :persistent
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(config = Jobi::Config::Rabbitmq.new) ⇒ Rabbitmq

Returns a new instance of Rabbitmq.



15
16
17
18
# File 'lib/jobi/clients/rabbitmq.rb', line 15

def initialize(config = Jobi::Config::Rabbitmq.new)
  @connection = Bunny.new(config.to_h)
  @connection.start
end

Instance Method Details

#channelObject



20
21
22
# File 'lib/jobi/clients/rabbitmq.rb', line 20

def channel
  @channel ||= @connection.create_channel
end

#default_exchangeObject



24
25
26
# File 'lib/jobi/clients/rabbitmq.rb', line 24

def default_exchange
  @default_exchange ||= channel.default_exchange
end

#publish(message:, queue:, options: {}) ⇒ Object



33
34
35
# File 'lib/jobi/clients/rabbitmq.rb', line 33

def publish(message:, queue:, options: {})
  queue.publish(message, build_options(options, MESSAGE_OPTIONS))
end

#queue(name:, options: {}) ⇒ Object



28
29
30
31
# File 'lib/jobi/clients/rabbitmq.rb', line 28

def queue(name:, options: {})
  default_exchange
  channel.queue(name, build_options(options, QUEUE_OPTIONS))
end