[zeromq-dev] Pub/sub for a logger and multiprocessing
Frédéric
fma at gbiloba.org
Sat Jul 23 18:40:03 CEST 2016
Ok, I finally got something working!
I attached my code (hope it is allowed by the list robot). Feel free to
comment...
But In this example, I had ti use this code for the forwarder:
----------------------------------------------
context = zmq.Context.instance()
# Socket facing clients
frontend = context.socket(zmq.SUB)
frontend.bind("tcp://*:%d" % FRONTEND_PORT)
frontend.setsockopt(zmq.SUBSCRIBE, "")
# Socket facing services
backend = context.socket(zmq.PUB)
backend.bind("tcp://*:%d" % BACKEND_PORT)
zmq.device(zmq.FORWARDER, frontend, backend)
----------------------------------------------
(launched as target multiprocessing.Process).
If I try to use a zmq ProcessDevice, which seems to be more elegant, I
get:
ZMQError: Invalid argument
on the bind_out().
Here is the code:
----------------------------------------------
pd = zmq.devices.ProcessDevice(zmq.FORWARDER, zmq.SUB, zmq.PUB)
pd.bind_in("tcp://*:%d" % FRONTEND_PORT)
pd.setsockopt_in(zmq.SUBSCRIBE, "")
pd.bind_out("tcp://*.%d" % BACKEND_PORT)
pd.start()
----------------------------------------------
Where is the mistake? Looking at the source, it look like the same as
above code...
Last, I would also like to know the difference between zmq.Context(), and
zmq.Context.instance()? When should I use one or the other?
Thanks,
--
Frédéric
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pub_log.py
Type: text/x-python
Size: 3750 bytes
Desc: not available
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20160723/0c00b892/attachment.py>
More information about the zeromq-dev
mailing list