Skip to content

liujinliu/apns_worker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

apns_worker

A consumer, receive messages from queues, then push notification to target devices

USAGE

environment requirement

rabbitmq server
A asynchronous apns sdk module should be installed in you
environment(https://github.com/kernel1983/tornado_apns)

server start

python setup.py install
worker-apns-start #use --help to see the full options

example

#coding=utf-8
import logging
import sys
from tornado.ioloop import IOLoop
from stormed import Connection, Message
import json

mqhost = 'localhost'
mqvhost = 'apns'
mquser = 'apns'
mqpass = 'apns'
queuename = 'apns'
exchange = 'apns'
routing_key = 'worker.apns'
durable = True

def on_connect():
    ch = conn.channel()
    ch.queue_declare(queue=queuename, durable=durable)
    for i in range(10):
        dev_list = [('123456789%d' %i)]#token value of target device
        notification = {'content':'test push message'}
        para_notify = dict(appname='testapp', content=u'测试,请忽略',
                       sound='default', badge=0,token_list=dev_list,
                       item=notification)
        # delivery_mode=2 makes message persistent
        msg = Message(json.dumps(para_notify), delivery_mode=2)
        ch.publish(msg, exchange=exchange, routing_key=routing_key)
    conn.close(callback=done)
def done():
    print "message publish finish "
    io_loop.stop()
logging.basicConfig()
conn = Connection(host=mqhost, vhost=mqvhost,
                  username=mquser, password=mqpass)
conn.connect(on_connect)
io_loop = IOLoop.instance()
io_loop.start()

About

a platform work

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published