volttron.platform.messaging package¶
Submodules¶
volttron.platform.messaging.headers module¶
VOLTTRON platform™ messaging header name constants.
volttron.platform.messaging.health module¶
-
class
volttron.platform.messaging.health.
Status
[source]¶ Bases:
object
The Status objects wraps the context status and last reported into a small object that can be serialized and sent across the zmq message bus.
- There are two static methods for constructing Status objects:
- from_json() Expects a json string as input.
- build() Expects at least a status in the ACCEPTABLE_STATUS tuple.
The build() method also takes a context and a callback function that will be called when the status changes.
-
as_json
()[source]¶ Serializes the object to a json string.
- Note:
- Does not serialize the change callback function.
Returns:
-
static
build
(status, context=None, status_changed_callback=None)[source]¶ Constructs a Status object and initializes its state using the passed parameters.
Parameters: - status –
- context –
- status_changed_callback –
Returns:
-
context
¶
-
static
from_json
(data, status_changed_callback=None)[source]¶ Deserializes a Status object and returns it to the caller.
Parameters: - data –
- status_changed_callback –
Returns:
-
last_updated
¶
-
status
¶
volttron.platform.messaging.socket module¶
VOLTTRON platform™ messaging classes.
-
class
volttron.platform.messaging.socket.
Headers
(*args, **kwargs)[source]¶ Bases:
dict
Case-insensitive dictionary for HTTP-like headers.
-
dict
¶ Return a dictionary with originally-cased keys.
-
-
class
volttron.platform.messaging.socket.
Socket
(socket_type, context=None)[source]¶ Bases:
zmq.sugar.socket.Socket
ØMQ socket with additional agent messaging methods.
-
recv_message_ex
(flags=0)[source]¶ Receive a message as (content type, message) tuples.
Like recv_message(), returns a three tuple. However, the final message component contains a list of 2-tuples instead of a list of messages. These 2-tuples contain the content- type and the data.
-
send_message
(topic, headers, *msg_parts, **kwargs)[source]¶ Send a multipart message with topic and headers.
Send a multipart message on the socket with topic being a UTF-8 string, headers can be a dictionary or a Headers object, and msg_parts is the optional parts of the message. The media or content type of each message component should be included in the ‘Content-Type’ header which should be a list of MIME types or a string if there is only one message part.
-
send_message_ex
(topic, headers, *msg_tuples, **kwargs)[source]¶ Send messages given as (content-type, message) tuples.
Similar to the send_message method except that messages are given as 2-tuples with the MIME type as the first element and the message data as the second element.
-
send_string
(u, flags=0, copy=True, encoding='utf-8')[source]¶ Send a Python unicode string as a message with an encoding.
0MQ communicates with raw bytes, so you must encode/decode text (unicode on py2, str on py3) around 0MQ.
- u : Python unicode string (unicode on py2, str on py3)
- The unicode string to send.
- flags : int, optional
- Any valid flags for
Socket.send()
. - encoding : str [default: ‘utf-8’]
- The encoding to be used
-
volttron.platform.messaging.topics module¶
VOLTTRON platform™ topic templates.
Templates of standard topics. Fields in the templates are replaced by calling the template with the field value included in the keyword arguments. Fields are replaced from left to right as long as a replacement can be made. Once a field is reached which cannot be replaced, everything in the replaced portion up to the last double slash is returned. Fields cannot be skipped, but may be included unsubstituted by using None for the field value. Below are some examples to demonstrate.
>>> T = _('root/{top}//{middle}//{bottom}')
>>> T()
Topic(u'root')
>>> T(top='first')
Topic(u'root/first')
>>> T(top='first', middle='second')
Topic(u'root/first/second')
>>> T(top='first', middle='second', bottom='third')
Topic(u'root/first/second/third')
>>> unicode(T(top='first', middle='second', bottom='third'))
u'root/first/second/third'
>>> T(top='first', bottom='third')
ValueError: unused keyword argument: bottom
>>> T(top='first', middle=None, bottom='third')
Topic(u'root/first/{middle}/third')
>>> T(top='first', middle=None, bottom='third')(middle='.')
Topic(u'root/first/third')
>>> T(top='first', middle=None, bottom='third')(middle='..')
Topic(u'root/third')
>>> T._(top='first', middle=None, bottom='third')
Topic(u'root/first//{middle}//third')