Need multiple apn_sender daemons #11

pctj101 opened this Issue Aug 30, 2011 · 17 comments


None yet
5 participants

pctj101 commented Aug 30, 2011

Say I have 1 server running several rails apps.

Each rails app has it's own Apple Push Notification messages, each bound for a different application, thus different PEM certificates.

It seems that apn_sender doesn't start multiple times, nor can I specify during APN.notify which PEM certificate to use.

I'm more than willing to help mod, but I could use some guidance as to how you'd like me to do it (before I just slam a bunch of keys into your redis namespace)

pctj101 commented Aug 30, 2011

FYI, I even have 1 rails app sending APNs for multiple iOS apps. So it's multiple apn_sender daemons per rails app (not just per OS instance)

pctj101 commented Aug 31, 2011

If it was me, I know one place I'd make a command line switch for is this queue_name variable.

However, I'm not sure the best way to modify APN.Notify() hmm!

apn_sender / lib / apn / queue_name.rb

module APN

Change this to modify the queue from which notification jobs are pushed and pulled

QUEUE_NAME = :apple_push_notifications

pctj101 commented Aug 31, 2011

This is where I'm stuck so far:

It seems that @Queue is set way too early in the process to take further input.
Maybe we can modify def self.perform(token, opts) to set @Queue to something else.
Since we don't absolutely know upon invoking APN.Notify() which queue name we are sending a message to, maybe we can just add a parameter there. In the options, we already pass a hash list of things like :badge, :alert, and so forth. Maybe we'll just add :queue => "your queue name" and we'd just use that inside APN::NotificationJob.perform(token, opts)

I'm gonna think about this a bit before I go ruin everyone's day. Let me know if you have any feedback.

apn_sender / lib / apn / notification_job.rb

module APN

This is the class that's actually enqueued via Resque when user calls +APN.notify+.

It gets added to the +apple_server_notifications+ Resque queue, which should only be operated on by

workers of the +APN::Sender+ class.

class NotificationJob
# Behind the scenes, this is the name of our Resque queue

# Build a notification from arguments and send to Apple
def self.perform(token, opts)
  msg =, opts)
  raise "Invalid notification options (did you provide :alert, :badge, or :sound?): #{opts.inspect}" unless msg.valid?

  worker.send_to_apple( msg )

pctj101 commented Aug 31, 2011

Aaah, looks like this guy already did a lot of the work I was thinking of.


pctj101 commented Aug 31, 2011

Okay merged that guy's stuff with your current code.

Not yet tested... I barely know what I'm doing.

pctj101 commented Aug 31, 2011

Okay merged in a bunch more in regards to rails 3 and certificate passwords.

totally not tested! just visual code merge!

What's that status on this. I think this would be pretty useful.

pctj101 commented Sep 3, 2011

Hey man, I got as far as merging a few forks of this project together, and keeping the most solid looking pieces of code. I haven't had time to test the merge.

One thing for sure is you have to run a different apn_sender for each certificate.

Wouldn't it be awesome to run one daemon with all the app bundle_id's and certs? Okay well one step at a time. You can take a look at my fork to see how far I got.

pctj101 commented Sep 3, 2011

Just tested and pushed my changes to my fork... take a look and see if it works for you. Very lightly tested.

Cool. I'll have a look, maybe write some tests. Appreciate it.

pctj101 commented Sep 4, 2011

Yeah if you have time to write a few tests, that would be awesome. It's something I haven't had a chance to really "learn", so I could really use the help.

Have a great weekend!

pctj101 commented Sep 7, 2011

code changes seem to be working, pull request submitted


kdonovan commented Sep 19, 2011

Great idea! Unfortunately the pull request was too monolithic and untested for me to merge, and I won't be developing with this library for another few months while projects rollover so there'll be a delay if/before I can reimplement these bits independently.

Thanks again for your help w/ this pctj101, sorry I wasn't able to pull it directly.

A note for future devs who come across this: check out the network if you want any particular features -- a number of branches contain some great stuff!

pctj101 commented Sep 24, 2011

Hey no problem. Thanks for taking a peek anyways!

tboyko commented May 14, 2013

@pctj101 May I suggest taking a look at the AppleShove gem? I used apn_sender for quite some time, but ended up writing my own gem when I developed the need to handle multiple push certificates.

pctj101 commented May 15, 2013

@tboyko Thanks for the tip! I'll try to give it a shot next week!

tboyko commented May 15, 2013

@pctj101 I realize that I'm a little late on a response, but figured it would be helpful for future readers. Good to hear it may help you too!

arthurnn closed this Jun 1, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment