Skip to content

Commit

Permalink
Change naming to barong.postmaster.event.mailer and turn off manual_a…
Browse files Browse the repository at this point in the history
…ck for events
  • Loading branch information
Yehor Chumak authored and Camille committed Aug 3, 2020
1 parent 922465c commit 747032f
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions app/services/event_mailer.rb
Expand Up @@ -21,17 +21,21 @@ def call
def listen
unlisten

@bunny_session = Bunny::Session.new(rabbitmq_credentials).tap(&:start)
@bunny_session = Bunny::Session.new(rabbitmq_credentials).tap do |session|
session.start
Kernel.at_exit { session.stop }
end

@bunny_channel = @bunny_session.channel

queue = @bunny_channel.queue('', auto_delete: true, durable: true)
queue = @bunny_channel.queue('barong.postmaster.event.mailer', auto_delete: false, durable: true)
@events.each do |event|
exchange = @bunny_channel.direct(@exchanges[event[:exchange].to_sym][:name])
queue.bind(exchange, routing_key: event[:key])
end

Rails.logger.info { 'Listening for events.' }
queue.subscribe(manual_ack: true, block: true, &method(:handle_message))
queue.subscribe(manual_ack: false, block: true, &method(:handle_message))
end

def unlisten
Expand Down Expand Up @@ -107,7 +111,6 @@ def handle_message(delivery_info, _metadata, payload)
}

Postmaster.process_payload(params).deliver_now
@bunny_channel.acknowledge(delivery_info.delivery_tag, false)
rescue StandardError => e
Rails.logger.error { e.inspect }

Expand Down

0 comments on commit 747032f

Please sign in to comment.