Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'bunny'
- module AMQP
- # Will make connection to the amqp client and create feed job which will
- # process data accordingly
- class Listner < ApplicationInteraction
- object :session, default: nil, class: Bunny::Session
- set_callback :validate, :after, -> { set_connection }
- def execute
- session.close if session.present?
- supervise_amqp_access do
- @retries ||= 0
- puts "$amqp_conn.inspect"
- $amqp_conn.start
- ch = $amqp_conn.channel
- queue = ch.queue('', exclusive: true)
- ch.queue_bind(queue.name, 'unifiedfeed', routing_key: '#')
- queue.subscribe(manual_ack: true, block: true) do |delivery_info, properties, payload|
- puts "#{delivery_info.inspect}"
- end
- put "outside execute ===================="
- $amqp_conn
- end
- end
- private
- def set_connection
- STDOUT.sync = true
- $amqp_conn = Bunny.new(
- host: 'mq.betradar.com',
- vhost: '/unifiedfeed/21951',
- port: 5671,
- user: api_key,
- password: api_key,
- ssl: true,
- verify_peer: false,
- verify_peer_name: false,
- allow_self_signed: true
- )
- end
- def api_key
- @api_key ||= Figaro.env.betradar_api_key
- end
- def supervise_amqp_access
- yield
- rescue ::StandardError => exception
- # AvantageSetting.suspend_betting
- $amqp_conn.close
- retry if (@retries += 1) < 3
- custom_error_logger(exception)
- end
- def custom_error_logger(exception)
- Honeybadger.notify(
- "[AMQP Listner Error] : [#{exception.class}] : [#{exception.cause}]",
- class_name: exception.class
- )
- AmqpClientErrorMailer.client_error(
- Figaro.env.developers_mail, exception.class.name, exception.cause,
- Time.zone.now.to_s
- ).deliver_later
- end
- end
- end
Add Comment
Please, Sign In to add comment