- msg id frame
- data = the data (json format) for the action
The message id is build from a couple of parts
- category = string to subscribe to
- timestamp = str(time()).replace(‘.’,’_’)
- version = 0_1
example:
- category = plugin.status
- timestamp = 1371476851_54
- version = 0_1
plugin.status.1371476851_54.0_1
The content is a json encoded python dict
As domogik has a lot of different components that need to publish or subscribe messages a system is required to forward the messages.
The dmg_forwarder was build for this, the forwarder listens on 2 different ports, on for the publisher clients and one for the subscribed clients. So all clinets (domogik components) that publish a messages will need to connect to the publisher listing port, the forwarder will then broadcast this message to all clients (domogik components) that are connected on the subscriber port.
The subscribing to certain messages is done on the client side, by using the subscribe socket of zmq.
The MQPub class is used to publish messages onto the pub/sub network.
The MQSyncSub class is used to subscribe to certain messages on the pub/sub network.
Then there is a blocking methode called wait_for_event, this method will block until a message is received that matches one of the category_filters.
The MQAsyncSub class is used to subscribe to certain messages on the pub/sub network.
The on_message callback will be called when a message is received that matches one of the category_filters. The on_message callback has 2 parameters:
- msg_id = is the message id of the message
- content = a python object (probebly a dict) that represent the json decoded message content