[zeromq-dev] Help needed choosing socket strategy

Adrian Ribao aribao at gmail.com
Tue Dec 4 21:38:03 CET 2012


Hello everybody,

my name is Adrián Ribao, i'm a python developer learning zeromq.

I'm reading the guide, which is quite fun :) and I'm really impressed with
the awesome job done with zeromq. Thank you for that!

I'm creating a notification system for a website, and at this moment it's
working ok but I'm sure that I did it wrong. Get ready for some newbie
questions.

The problem to solve is quite standard: Show notifications in the site
almost in real time.

There is a long polling ajax connection waiting for notifications. The
notifications are created for example when saving some data in the database.

I have implemented a PUB/SUB socket. The ajax view uses the SUB socket and
the notifier uses PUB.

PUB connects to tcp://localhost:5555 and SUB to tcp://localhost:5556

I created a simple proxy to bind those endpoints. These is how it looks:

----
context = zmq.Context()
print "Starting the proxy..."

# Listen for events
sub = context.socket(zmq.SUB)
sub.bind("tcp://*:5555")
sub.setsockopt(zmq.SUBSCRIBE, '')

# Emit events
pub = context.socket(zmq.PUB)
pub.bind("tcp://*:5556")

while True:
    message = sub.recv()
    pub.send(message)
----

I think this is wrong. It works but i don't like it.

How should I implement this? Is correct the use of PUB/SUB sockets?
How should I create a proxy that scales well?

note: I use zmq.SUBSCRIBE a lot to manage notification types.

Thank you very much for your help. I feel that zeromq is a great piece of
software but I'm a little bit confused yet.

Adrián
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20121204/18218153/attachment.htm>


More information about the zeromq-dev mailing list