class RabbitmqClient::PublisherJob

Publisher class is responsible for publishing events to rabbitmq exhanges

Public Instance Methods

perform(registry, session_pool, data, options) click to toggle source
# File lib/rabbitmq_client/publisher_job.rb, line 11
def perform(registry, session_pool, data, options)
  handle_publish_event(registry, session_pool, data, options)
rescue StandardError => e
  notify('network_error', error: e, options: options)
  raise
end

Private Instance Methods

handle_publish_event(registry, session_pool, data, options) click to toggle source
# File lib/rabbitmq_client/publisher_job.rb, line 20
def handle_publish_event(registry, session_pool, data, options)
  exchange = registry.find(options.fetch(:exchange_name, nil))
  session_pool.with do |session|
    session.start
    channel = session.create_channel
    channel.confirm_select
    message = MessagePublisher.new(data, exchange, channel, options)
    message.publish
    message.wait_for_confirms
    channel.close
  end
end
notify(event, payload = {}) click to toggle source
# File lib/rabbitmq_client/publisher_job.rb, line 33
def notify(event, payload = {})
  ActiveSupport::Notifications.instrument(
    "#{event}.rabbitmq_client",
    payload
  )
end