Class: JackRabbit::Producer
- Inherits:
-
Object
- Object
- JackRabbit::Producer
- Defined in:
- lib/jack_rabbit/producer.rb
Constant Summary
Constants included from Logging
Constants included from Backoff
Instance Method Summary collapse
- #connect(uri, options = {}) ⇒ Object
- #disconnect ⇒ Object
-
#initialize(logger = nil) ⇒ Producer
constructor
A new instance of Producer.
- #publish(exchange, type, key, message, headers = {}) ⇒ Object
Methods included from Logging
Methods included from 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, = {}) @connection = open_connection(uri, ) @channel = open_channel(@connection, ) end |
#disconnect ⇒ Object
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, , headers = {}) with_backoff(Java::ComRabbitmqClient::AlreadyClosedException) do debug('publishing to %s:%s with %s...' % [ type, exchange, key ]) @channel .create_exchange(exchange, { type: type }) .publish(, headers.merge(routing_key: key)) end end |