mardi 5 mai 2015

How to store the messages, when other person is offline, so when he comes online he gets all the messages?

How to store the messages, when Sub(subscriber) is offline, so when he comes online he gets all the messages?

Sub.py

# -*- coding: utf-8 -*-
# collects data from remote publisher and sends it to local subscriber 
from gevent_zeromq import zmq
ctx = zmq.Context()
s = ctx.socket(zmq.SUB)
s.connect("tcp://127.0.0.1:5567")
s.setsockopt(zmq.SUBSCRIBE,'')
while True:
    print 'waiting...'
    msg = s.recv()
    print 'received:', msg
s.close()
ctx.term()

Pub.py

def NOTIFICATION(request):
    if request.method == 'GET':
        return render_to_response('notifications.html',context)
    if request.method == 'POST':
        message_json = json.dumps(request.data)
        message_load = json.loads(message_json)
        message = {message_load['msg']}
        ctx = zmq.Context()
        publisher = ctx.socket(zmq.PUB)
        publisher.bind("tcp://*:5566")
        time.sleep(1)
        while True:
             publisher.send_multipart("message:%s" % str(message))
             time.sleep(1)
             publisher.close()
        ctx.term() 
    return Response('',status=200)

This code is working properly for message sending. But, When publisher sends the messages, if subscriber is offline, subsciber will not receive the messages. He will only receive when he is online. What to write in the code so that when subscriber comes online he receives all messages what he is not receiving in this case.

Aucun commentaire:

Enregistrer un commentaire