Class: GovukSeedCrawler::AmqpClient
- Inherits:
-
Object
- Object
- GovukSeedCrawler::AmqpClient
- Defined in:
- lib/govuk_seed_crawler/amqp_client.rb
Instance Attribute Summary collapse
-
#channel ⇒ Object
readonly
Returns the value of attribute channel.
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(connection_options = {}) ⇒ AmqpClient
constructor
A new instance of AmqpClient.
- #publish(exchange, topic, body) ⇒ Object
Constructor Details
#initialize(connection_options = {}) ⇒ AmqpClient
Returns a new instance of AmqpClient.
7 8 9 10 11 |
# File 'lib/govuk_seed_crawler/amqp_client.rb', line 7 def initialize( = {}) @conn = Bunny.new() @conn.start @channel = @conn.create_channel end |
Instance Attribute Details
#channel ⇒ Object (readonly)
Returns the value of attribute channel.
5 6 7 |
# File 'lib/govuk_seed_crawler/amqp_client.rb', line 5 def channel @channel end |
Instance Method Details
#close ⇒ Object
13 14 15 |
# File 'lib/govuk_seed_crawler/amqp_client.rb', line 13 def close @conn.close end |
#publish(exchange, topic, body) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/govuk_seed_crawler/amqp_client.rb', line 17 def publish(exchange, topic, body) raise "Exchange cannot be nil" if exchange.nil? raise "Topic cannot be nil" if topic.nil? raise "Message body cannot be nil" if body.nil? GovukSeedCrawler.logger.debug("Publishing '#{body}' to topic '#{topic}'") @channel.topic(exchange, durable: true) .publish(body, routing_key: topic) end |