devices¶
Functions¶
-
zmq.
device
(device_type, frontend, backend)¶ Start a zeromq device.
Deprecated since version libzmq-3.2: Use zmq.proxy
Parameters: device_type : (QUEUE, FORWARDER, STREAMER)
The type of device to start.
frontend : Socket
The Socket instance for the incoming traffic.
backend : Socket
The Socket instance for the outbound traffic.
-
zmq.
proxy
(frontend, backend, capture)¶ Start a zeromq proxy (replacement for device).
New in version libzmq-3.2.
New in version 13.0.
Parameters: frontend : Socket
The Socket instance for the incoming traffic.
backend : Socket
The Socket instance for the outbound traffic.
capture : Socket (optional)
The Socket instance for capturing traffic.
Module: zmq.devices
¶
0MQ Device classes for running in background threads or processes.
Base Devices¶
Device
¶
-
class
zmq.devices.
Device
(device_type=3, in_type=None, out_type=None)¶ A 0MQ Device to be run in the background.
You do not pass Socket instances to this, but rather Socket types:
Device(device_type, in_socket_type, out_socket_type)
For instance:
dev = Device(zmq.QUEUE, zmq.DEALER, zmq.ROUTER)
Similar to zmq.device, but socket types instead of sockets themselves are passed, and the sockets are created in the work thread, to avoid issues with thread safety. As a result, additional bind_{in|out} and connect_{in|out} methods and setsockopt_{in|out} allow users to specify connections for the sockets.
Parameters: device_type : int
The 0MQ Device type
{in|out}_type : int
zmq socket types, to be passed later to context.socket(). e.g. zmq.PUB, zmq.SUB, zmq.REQ. If out_type is < 0, then in_socket is used for both in_socket and out_socket.
Attributes
daemon (int) sets whether the thread should be run as a daemon Default is true, because if it is false, the thread will not exit unless it is killed Methods
bind_{in_out}(iface) passthrough for {in|out}_socket.bind(iface)
, to be called in the threadconnect_{in_out}(iface) passthrough for {in|out}_socket.connect(iface)
, to be called in the threadsetsockopt_{in_out}(opt,value) passthrough for {in|out}_socket.setsockopt(opt, value)
, to be called in the thread-
bind_in
(addr)¶ Enqueue ZMQ address for binding on in_socket.
See zmq.Socket.bind for details.
-
bind_out
(addr)¶ Enqueue ZMQ address for binding on out_socket.
See zmq.Socket.bind for details.
-
connect_in
(addr)¶ Enqueue ZMQ address for connecting on in_socket.
See zmq.Socket.connect for details.
-
connect_out
(addr)¶ Enqueue ZMQ address for connecting on out_socket.
See zmq.Socket.connect for details.
-
join
(timeout=None)¶ wait for me to finish, like Thread.join.
Reimplemented appropriately by subclasses.
-
setsockopt_in
(opt, value)¶ Enqueue setsockopt(opt, value) for in_socket
See zmq.Socket.setsockopt for details.
-
setsockopt_out
(opt, value)¶ Enqueue setsockopt(opt, value) for out_socket
See zmq.Socket.setsockopt for details.
-
start
()¶ Start the device. Override me in subclass for other launchers.
-
ThreadDevice
¶
-
class
zmq.devices.
ThreadDevice
(device_type=3, in_type=None, out_type=None)¶ A Device that will be run in a background Thread.
See Device for details.
Attributes
launcher Methods
ProcessDevice
¶
-
class
zmq.devices.
ProcessDevice
(device_type=3, in_type=None, out_type=None)¶ A Device that will be run in a background Process.
See Device for details.
Attributes
launcher Methods
-
context_factory
(io_threads=1, **kwargs)¶ Callable that returns a context. Typically either Context.instance or Context, depending on whether the device should share the global instance or not.
Attributes
sockopts Methods
alias of
Context
-
Proxy Devices¶
Proxy
¶
-
class
zmq.devices.
Proxy
(in_type, out_type, mon_type=1)¶ Threadsafe Proxy object.
See zmq.devices.Device for most of the spec. This subclass adds a <method>_mon version of each <method>_{in|out} method, for configuring the monitor socket.
A Proxy is a 3-socket ZMQ Device that functions just like a QUEUE, except each message is also sent out on the monitor socket.
A PUB socket is the most logical choice for the mon_socket, but it is not required.
Methods
-
bind_mon
(addr)¶ Enqueue ZMQ address for binding on mon_socket.
See zmq.Socket.bind for details.
-
connect_mon
(addr)¶ Enqueue ZMQ address for connecting on mon_socket.
See zmq.Socket.bind for details.
-
setsockopt_mon
(opt, value)¶ Enqueue setsockopt(opt, value) for mon_socket
See zmq.Socket.setsockopt for details.
-
ThreadProxy
¶
-
class
zmq.devices.
ThreadProxy
(in_type, out_type, mon_type=1)¶ Proxy in a Thread. See Proxy for more.
Attributes
launcher Methods
ProcessProxy
¶
-
class
zmq.devices.
ProcessProxy
(in_type, out_type, mon_type=1)¶ Proxy in a Process. See Proxy for more.
Attributes
launcher Methods
MonitoredQueue Devices¶
-
zmq.devices.
monitored_queue
(in_socket, out_socket, mon_socket, in_prefix=b'in', out_prefix=b'out')¶ Start a monitored queue device.
A monitored queue is very similar to the zmq.proxy device (monitored queue came first).
Differences from zmq.proxy:
- monitored_queue supports both in and out being ROUTER sockets (via swapping IDENTITY prefixes).
- monitor messages are prefixed, making in and out messages distinguishable.
Parameters: in_socket : Socket
One of the sockets to the Queue. Its messages will be prefixed with ‘in’.
out_socket : Socket
One of the sockets to the Queue. Its messages will be prefixed with ‘out’. The only difference between in/out socket is this prefix.
mon_socket : Socket
This socket sends out every message received by each of the others with an in/out prefix specifying which one it was.
in_prefix : str
Prefix added to broadcast messages from in_socket.
out_prefix : str
Prefix added to broadcast messages from out_socket.
MonitoredQueue
¶
-
class
zmq.devices.
MonitoredQueue
(in_type, out_type, mon_type=1, in_prefix='in', out_prefix='out')¶ Class for running monitored_queue in the background.
See zmq.devices.Device for most of the spec. MonitoredQueue differs from Proxy, only in that it adds a
prefix
to messages sent on the monitor socket, with a different prefix for each direction.MQ also supports ROUTER on both sides, which zmq.proxy does not.
If a message arrives on in_sock, it will be prefixed with in_prefix on the monitor socket. If it arrives on out_sock, it will be prefixed with out_prefix.
A PUB socket is the most logical choice for the mon_socket, but it is not required.
Methods
ThreadMonitoredQueue
¶
-
class
zmq.devices.
ThreadMonitoredQueue
(in_type, out_type, mon_type=1, in_prefix='in', out_prefix='out')¶ Run zmq.monitored_queue in a background thread.
See MonitoredQueue and Proxy for details.
Attributes
launcher Methods
ProcessMonitoredQueue
¶
-
class
zmq.devices.
ProcessMonitoredQueue
(in_type, out_type, mon_type=1, in_prefix='in', out_prefix='out')¶ Run zmq.monitored_queue in a background thread.
See MonitoredQueue and Proxy for details.
Attributes
launcher Methods