Class: Tackle::Publisher
- Inherits:
-
Object
- Object
- Tackle::Publisher
- Defined in:
- lib/tackle/publisher.rb
Instance Method Summary collapse
-
#initialize(url, exchange_name, routing_key, logger, connection = nil) ⇒ Publisher
constructor
A new instance of Publisher.
- #publish(message) ⇒ Object
Constructor Details
#initialize(url, exchange_name, routing_key, logger, connection = nil) ⇒ Publisher
Returns a new instance of Publisher.
4 5 6 7 8 9 10 |
# File 'lib/tackle/publisher.rb', line 4 def initialize(url, exchange_name, routing_key, logger, connection = nil) @url = url @exchange_name = exchange_name @routing_key = routing_key @logger = logger @connection = connection end |
Instance Method Details
#publish(message) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/tackle/publisher.rb', line 12 def publish() connection = Tackle::Connection.new(@url, nil, @logger, @connection) @logger.info("Declaring exchange='#{@exchange_name}'") exchange = connection.channel.direct(@exchange_name, :durable => true) @logger.info("Declared exchange='#{@exchange_name}'") @logger.info("Publishing message exchange='#{@exchange_name}' routing_key='#{@routing_key}'") exchange.publish(, :routing_key => @routing_key, :persistent => true) @logger.info("Publishing message finished exchange='#{@exchange_name}' routing_key='#{@routing_key}'") ensure connection.close unless connection.nil? end |