class GovukSeedCrawler::AmqpClient

Attributes

channel[R]

Public Class Methods

new(connection_options = {}) click to toggle source
# 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

Public Instance Methods

close() click to toggle source
# File lib/govuk_seed_crawler/amqp_client.rb, line 13
def close
  @conn.close
end
publish(exchange, topic, body) click to toggle source
# 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