zmqwrapper Package

zmqwrapper Package

constants Module

The message types that are supported by the package are -

  • RAW
  • PYOBJ
  • JSON
  • MULTIPART
  • STRING
  • UNICODE

This map to the same types supported by pyzmq

consumers Module

class zmqwrapper.consumers.Consumer(address, callback, message_type)[source]

Bases: zmqwrapper.sockets.ClientConnection

Requestor that that can send requests of given type

Args:
  • address: the address to bind to
  • callback: the callback to invoke for every reply
  • message_type: the type of request to send
start()[source]

Start a thread that consumes the replies and invokes the callback

stop()[source]

Stop the consumer thread

zmqwrapper.consumers.consumer(address, callback, message_type)[source]

Creates a consumer binding to the given address pull messages. The callback is invoked for every reply received.

Args:
  • address: the address to bind the PULL socket to.
  • callback: the callback to invoke for every message. Must accept 1 variables - the message
  • message_type: the type of message to receive

producers Module

class zmqwrapper.producers.Producer(address)[source]

Bases: zmqwrapper.sockets.ServerConnection

Requestor that that can respond to requests of given type

Args:
  • address: the address to bind to
push(message, message_type)[source]

Send a reply message of the given type

Args:
  • message: the message to publish
  • message_type: the type of message being sent
zmqwrapper.producers.producer(address)[source]

Creates a producer binding to the given address push messages. The callback is invoked for every request received.

Args:
  • address: the address to bind the PUSH socket to.

publishers Module

class zmqwrapper.publishers.Publisher(address)[source]

Bases: zmqwrapper.sockets.ServerConnection

Publisher that can send messages to ZMQ

Args:
  • address: the address to bind to
publish(message, message_type, topic='')[source]

Publish the message on the PUB socket with the given topic name.

Args:
  • message: the message to publish
  • message_type: the type of message being sent
  • topic: the topic on which to send the message. Defaults to ‘’.
zmqwrapper.publishers.publisher(address)[source]

Creates a publisher binding to the given port number.

Args:
  • address: the address to bind the PUB socket to.

repliers Module

class zmqwrapper.repliers.Replier(address, callback, message_type)[source]

Bases: zmqwrapper.sockets.ServerConnection

Requestor that that can respond to requests of given type

Args:
  • address: the address to bind to
  • callback: the callback to invoke for every request
  • message_type: the type of reply to send
reply(message, message_type)[source]

Send a reply message of the given type

Args:
  • message: the message to publish
  • message_type: the type of message being sent
start()[source]

Start a thread that consumes the requests and invokes the callback

stop()[source]

Stop the consumer thread

zmqwrapper.repliers.replier(address, callback, message_type)[source]

Creates a replier binding to the given address send replies. The callback is invoked for every request received.

Args:
  • address: the address to bind the REP socket to.
  • callback: the callback to invoke for every message. Must accept 2 variables - message and the replier
  • message_type: the type of message to receive

requestors Module

class zmqwrapper.requestors.Requestor(address, callback, message_type)[source]

Bases: zmqwrapper.sockets.ClientConnection

Requestor that that can send requests of given type

Args:
  • address: the address to bind to
  • callback: the callback to invoke for every reply
  • message_type: the type of request to send
request(message, message_type)[source]

Send a request message of the given type

Args:
  • message: the message to publish
  • message_type: the type of message being sent
start()[source]

Start a thread that consumes the replies and invokes the callback

stop()[source]

Stop the consumer thread

zmqwrapper.requestors.requestor(address, callback, message_type)[source]

Creates a requestor binding to the given address send requests. The callback is invoked for every reply received.

Args:
  • address: the address to bind the REQ socket to.
  • callback: the callback to invoke for every message. Must accept 2 variables - message and the requestor
  • message_type: the type of message to receive

sockets Module

class zmqwrapper.sockets.ClientConnection(address, socket_type)[source]

Bases: zmqwrapper.sockets.SendReceiveMixin, object

Creates a client side socket of given type.

Args:
  • address: the address to use
  • socket_type: the tyoe of socket to open
close()[source]

Close the socket connection.

sock()[source]

Returns the zmq socket object being used for the connection. This can be used to receive messages with additional flags etc.

Returns:
  • The underlying zmq socket
class zmqwrapper.sockets.SendReceiveMixin[source]

Provides send or receive functionality for the sockets

receive(message_type)[source]

Receive the message of the specified type and retun

Args:
  • message_type: the type of the message to receive
Returns:
  • the topic of the message
  • the message received from the socket
send(message, message_type, topic='')[source]

Send the message on the socket.

Args:
  • message: the message to publish
  • message_type: the type of message being sent
  • topic: the topic on which to send the message. Defaults to ‘’.
class zmqwrapper.sockets.ServerConnection(address, socket_type)[source]

Bases: zmqwrapper.sockets.SendReceiveMixin, object

Creates a server side socket of given type.

Args:
  • address: the address to use
  • socket_type: the tyoe of socket to open
close()[source]

Close the socket connection.

sock()[source]

Returns the zmq socket object being used for the connection. This can be used to send messages with additional flags etc.

Returns:
  • The underlying zmq socket

subscribers Module

class zmqwrapper.subscribers.Subscriber(address, topics, callback, message_type)[source]

Bases: zmqwrapper.sockets.ClientConnection

Subscriber that can read messages from ZMQ

Args:
  • address: the address to bind to
  • topics: the topics to subscribe
  • callback: the callback to invoke for every message
  • message_type: the type of message to receive
start()[source]

Start a thread that consumes the messages and invokes the callback

stop()[source]

Stop the consumer thread

zmqwrapper.subscribers.subscriber(address, topics, callback, message_type)[source]

Creates a subscriber binding to the given address and subscribe the given topics. The callback is invoked for every message received.

Args:
  • address: the address to bind the PUB socket to.
  • topics: the topics to subscribe
  • callback: the callback to invoke for every message. Must accept 2 variables - topic and message
  • message_type: the type of message to receive

test_pubsub Module

zmqwrapper.test_pubsub.test_init_basic_subscribe()[source]
zmqwrapper.test_pubsub.test_init_publisher()[source]
zmqwrapper.test_pubsub.test_init_subscriber()[source]

test_pushpull Module

zmqwrapper.test_pushpull.test_init_basic_consume()[source]
zmqwrapper.test_pushpull.test_init_consumer()[source]
zmqwrapper.test_pushpull.test_init_producer()[source]

test_reqrep Module

zmqwrapper.test_reqrep.test_init_basic_reqrep()[source]
zmqwrapper.test_reqrep.test_init_replier()[source]
zmqwrapper.test_reqrep.test_init_requestor()[source]