Skip to content

Instantly share code, notes, and snippets.

@squeedee
Created November 10, 2011 23:26
Show Gist options
  • Select an option

  • Save squeedee/1356610 to your computer and use it in GitHub Desktop.

Select an option

Save squeedee/1356610 to your computer and use it in GitHub Desktop.
require "rubygems"
require "amqp"
require 'msgpack'
require 'base64'
require "em-apn"
EXCHANGE = "push_notification"
AUTO_DELETE = false
DURABLE = true
ROUTING_KEY = "apple"
QUEUE = "apple:apple"
KEY_CERT_CHAIN_THING = "../../pipeline/ssl/apple_push_notification_development.pem"
EventMachine.run do
puts "Machine running"
@apn= EM::APN::Client.connect(
:key => KEY_CERT_CHAIN_THING,
:cert => KEY_CERT_CHAIN_THING
)
@apn.on_receipt do |data|
puts "Got data: #{data}"
end
connection = AMQP.connect
channel = AMQP::Channel.new(connection)
exchange = channel.topic(EXCHANGE, :auto_delete => AUTO_DELETE, :durable => DURABLE)
queue = channel.queue(QUEUE, :auto_delete => AUTO_DELETE, :durable => DURABLE).bind(exchange, :routing_key => ROUTING_KEY)
queue.subscribe(:ack=>false) do |headers, payload|
original_message = MessagePack.unpack(Base64.decode64 payload)
puts "Message for apple: #{original_message.to_yaml}, routing key is #{headers.routing_key}"
token = original_message.delete('token').gsub(/\s+/, "")
notification = EM::APN::Notification.new(token, original_message)
notification.identifier = 256
@apn.deliver(notification)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment