EventMachine.run do
send_apns = SendApnsContext.new
AMQP.connect(@rabbit_uri) do |connection|
#connection.on_tcp_connection_loss do |conn, settings| ...
AMQP::Channel.new(connection, auto_recovery: true) do |channel|
#channel.on_error do |ch, channel_close| ...
channel.direct(@apns_channel, durable: true) do |exchange|
AMQP::Queue.new(channel, @apns_queue, durable: true) do |queue|
queue.bind(exchange, routing_key: @apns_routing_key)
queue.subscribe do |metadata, payload| #(ack: true)
begin
send_apns.send_notification(payload) #retries 2 times - regular sockets
rescue Errno::ECONNREFUSED
Rails.logger.error "ApnsService trouble sending #{payload} retrying in 5 seconds"
sleep(5) #BAD
retry
end
end
end
end
end