Class: JackRabbit::Producer

Inherits:
Object
  • Object
show all
Includes:
Backoff, Client, Logging
Defined in:
lib/jack_rabbit/producer.rb

Constant Summary

Constants included from Logging

Logging::TAG

Constants included from Backoff

Backoff::MAX

Instance Method Summary collapse

Methods included from Logging

#set_logger

Methods included from Backoff

#with_backoff

Constructor Details

#initialize(logger = nil) ⇒ Producer

Returns a new instance of Producer.



10
11
12
# File 'lib/jack_rabbit/producer.rb', line 10

def initialize(logger = nil)
  @logger = logger
end

Instance Method Details

#connect(uri, options = {}) ⇒ Object



14
15
16
17
# File 'lib/jack_rabbit/producer.rb', line 14

def connect(uri, options = {})
  @connection = open_connection(uri, options)
  @channel = open_channel(@connection, options)
end

#disconnectObject



28
29
30
31
# File 'lib/jack_rabbit/producer.rb', line 28

def disconnect
  @channel.close
  @connection.close
end

#publish(exchange, type, key, message, headers = {}) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/jack_rabbit/producer.rb', line 19

def publish(exchange, type, key, message, headers = {})
  with_backoff(Java::ComRabbitmqClient::AlreadyClosedException) do
    debug('publishing to %s:%s with %s...' % [ type, exchange, key ])
    @channel
      .create_exchange(exchange, { type: type })
      .publish(message, headers.merge(routing_key: key))
  end
end