Sha256: ddfb0c488bfb37db11688a91d6329d082b8c4ec7190b08e01b0134bc4e64d1b0

Contents?: true

Size: 933 Bytes

Versions: 2

Compression:

Stored size: 933 Bytes

Contents

require 'bunny'

module GeoConcerns
  class RabbitMessagingClient
    attr_reader :amqp_url
    def initialize(amqp_url)
      @amqp_url = amqp_url
    end

    def publish(message)
      exchange_type = JSON.parse(message)['exchange']
      send(exchange_type)
      @exchange.publish(message, persistent: true)
    rescue
      Rails.logger.warn "Unable to publish message to #{amqp_url}"
    end

    def geoblacklight
      exchange_name = Messaging.config['events']['exchange']['geoblacklight']
      @exchange ||= channel.fanout(exchange_name, durable: true)
    end

    def geoserver
      exchange_name = Messaging.config['events']['exchange']['geoserver']
      @exchange ||= channel.fanout(exchange_name, durable: true)
    end

    private

      def bunny_client
        @bunny_client ||= Bunny.new(amqp_url).tap(&:start)
      end

      def channel
        @channel ||= bunny_client.create_channel
      end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
geo_concerns-0.1.1 app/services/geo_concerns/rabbit_messaging_client.rb
geo_concerns-0.1.0 app/services/geo_concerns/rabbit_messaging_client.rb