Transport Library¶
-
class
dploylib.transport.
Context
(zmq_context)¶ A wrapper around a zeromq Context
Parameters: zmq_context – The zeromq context
-
class
dploylib.transport.
Socket
(zmq_socket, zmq_context)¶ A wrapper around a zeromq Socket
Parameters: - zmq_socket – The underlying zeromq socket
- zmq_context – The zeromq context related to the zeromq socket
-
bind
(uri)¶ Bind the socket to a URI
-
classmethod
bind_new
(socket_type, uri, options=None, context=None)¶ Create and bind a new socket
Parameters:
-
bind_to_random
(uri, min_port=None, max_port=None, max_tries=None)¶ Bind the socket to a random port at URI
-
connect
(uri)¶ Connect the socket to a URI
-
classmethod
connect_new
(socket_type, uri, options=None, context=None)¶ Create and connect a new socket
Parameters:
-
classmethod
new
(socket_type, context=None)¶ Creates a new socket
Parameters:
-
receive_envelope
()¶ Receive an
Envelope
-
receive_obj
(handler)¶ Receives an
Envelope
and calls an object to handle the envelope data.Parameters: handler – A callable that transforms the data into an object
-
receive_text
()¶ Convenience method to receive plain text
-
send_envelope
(envelope)¶ Send an
Envelope
-
send_obj
(obj, id='')¶ Sends encoded an object as encoded data.
The encoding can be anything. Default is JSON. This could change later and should not affect communications.
The object must implement the method __serialize__
Parameters: - obj – An object that implements a serialize method that returns any data that can be serialized (ie. lists, dict, strings, ints)
- id – The id for the envelope. Defaults to ‘’
-
send_text
(text, id='')¶ Sends a simple text message
Parameters: - text – Text to send
- id – The id for the envelope. Defaults to ‘’
-
set_option
(option, value)¶ Set a socket option
Parameters: - option (str) – Name of the option
- value (str or int. Depends on the option.) – Value of the option
-
class
dploylib.transport.
Envelope
(id, mimetype, data, request_frames=None)¶ Dploy’s message envelope.
This is a standard definition so that all messages are decoded the same way. The envelope is as follows (for the time being):
----------------------- | any request frames | ----------------------- | empty frame if above | ----------------------- | id - a string or '' | ----------------------- | mimetype | ----------------------- | body | -----------------------
Note
The
id
portion of the envelope may seem like unnecessary data, but it allows the envelope to be used in pub-sub effectively.Parameters: - id (str) – A string id for the envelope
- mimetype (str) – The mimetype for the envelope
- data – The envelope’s body
-
classmethod
from_raw
(raw)¶ Creates an envelope from a tuple or list
Parameters: raw (tuple or list) – Raw data for an envelope
-
classmethod
new
(mimetype, data, id='', request_frames=None)¶ Create a new envelope. This is the preferred way to create a new envelope.
Parameters: - mimetype – The mimetype for the envelope
- data – The envelope’s body
- id – (optional) A string id for the envelope. Defaults to ‘’
-
response_envelope
(mimetype, data, id=None)¶ Shortcut to create a response envelope from the current envelope
By default this will create an envelope with the same request_frames, id and mimetype as this envelope.
-
transfer_object
()¶ This is the object to be sent over the wire. The reverse of this is Envelope.from_raw
For zmq this should be an list
-
class
dploylib.transport.
PollLoop
(poller)¶ A custom poller that automatically routes the handling of poll events
The handlers of poll events are simply callables. This only handles POLLIN events at this time.