|
@ -5,6 +5,7 @@ try: |
|
|
import eventlet.green.zmq as zmq |
|
|
import eventlet.green.zmq as zmq |
|
|
except ImportError: |
|
|
except ImportError: |
|
|
zmq = None |
|
|
zmq = None |
|
|
|
|
|
import six |
|
|
|
|
|
|
|
|
from .pubsub_manager import PubSubManager |
|
|
from .pubsub_manager import PubSubManager |
|
|
|
|
|
|
|
@ -12,6 +13,9 @@ from .pubsub_manager import PubSubManager |
|
|
class ZmqManager(PubSubManager): # pragma: no cover |
|
|
class ZmqManager(PubSubManager): # pragma: no cover |
|
|
"""zmq based client manager. |
|
|
"""zmq based client manager. |
|
|
|
|
|
|
|
|
|
|
|
NOTE: this zmq implementation should be considered experimental at this |
|
|
|
|
|
time. At this time, eventlet is required to use zmq. |
|
|
|
|
|
|
|
|
This class implements a zmq backend for event sharing across multiple |
|
|
This class implements a zmq backend for event sharing across multiple |
|
|
processes. To use a zmq backend, initialize the :class:`Server` instance as |
|
|
processes. To use a zmq backend, initialize the :class:`Server` instance as |
|
|
follows:: |
|
|
follows:: |
|
@ -27,25 +31,20 @@ class ZmqManager(PubSubManager): # pragma: no cover |
|
|
default of ``False`` initializes the class for emitting |
|
|
default of ``False`` initializes the class for emitting |
|
|
and receiving. |
|
|
and receiving. |
|
|
|
|
|
|
|
|
|
|
|
A zmq message broker must be running for the zmq_manager to work. |
|
|
|
|
|
you can write your own or adapt one from the following simple broker |
|
|
|
|
|
below:: |
|
|
|
|
|
|
|
|
N.B. |
|
|
import zmq |
|
|
a zmq message broker must be running for the zmq_manager to work. |
|
|
|
|
|
you can write your own or adapt one from the following simple broker below. |
|
|
|
|
|
port numbers in the broker must match port numbers in connection string. |
|
|
|
|
|
`` |
|
|
|
|
|
import zmq |
|
|
|
|
|
|
|
|
|
|
|
receiver = zmq.Context().socket(zmq.PULL) |
|
|
|
|
|
receiver.bind("tcp://*:5555") |
|
|
|
|
|
|
|
|
|
|
|
publisher = zmq.Context().socket(zmq.PUB) |
|
|
receiver = zmq.Context().socket(zmq.PULL) |
|
|
publisher.bind("tcp://*:5556") |
|
|
receiver.bind("tcp://*:5555") |
|
|
|
|
|
|
|
|
|
|
|
publisher = zmq.Context().socket(zmq.PUB) |
|
|
|
|
|
publisher.bind("tcp://*:5556") |
|
|
|
|
|
|
|
|
while True: |
|
|
while True: |
|
|
publisher.send(receiver.recv()) |
|
|
publisher.send(receiver.recv()) |
|
|
`` |
|
|
|
|
|
|
|
|
|
|
|
""" |
|
|
""" |
|
|
name = 'zmq' |
|
|
name = 'zmq' |
|
|
|
|
|
|
|
@ -97,7 +96,7 @@ class ZmqManager(PubSubManager): # pragma: no cover |
|
|
|
|
|
|
|
|
def _listen(self): |
|
|
def _listen(self): |
|
|
for message in self.zmq_listen(): |
|
|
for message in self.zmq_listen(): |
|
|
if isinstance(message, str): |
|
|
if isinstance(message, six.binary_type): |
|
|
try: |
|
|
try: |
|
|
message = pickle.loads(message) |
|
|
message = pickle.loads(message) |
|
|
except Exception: |
|
|
except Exception: |
|
|