Class: GovukSeedCrawler::AmqpClient

Inherits:
Object
  • Object
show all
Defined in:
lib/govuk_seed_crawler/amqp_client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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(connection_options = {})
  @conn = Bunny.new(connection_options)
  @conn.start
  @channel = @conn.create_channel
end

Instance Attribute Details

#channelObject (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

#closeObject



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