This is the developer guide for any further implementations of this library in another programming language.
Messages are simple dictionaries, represented in JSON format. Mandatory keys of a message are as follows:
- sender: Array of strings. First element is creator's, rest is forwarders'
id
's. - timestamp: Unix time stamp
- msg_id: a unique message id. practically concatenate
creator_id
andi
wherei
is sequence number of message - payload: a dictionary, described below.
Payload is basically in {'Subject': data}
format. Here are some examples:
-
To set
green-led
pin toTrue
, one must send the following message:Python:
msg = { 'IoMessage': { 'pin_name': 'green-led', 'val': True } }
Javascript:
var msg = { IoMessage: { pin_name: 'green-led', val: true } }
LiveScript:
msg = IoMessage: pin_name: \green-led, val: on
So, a full message should look like this:
{"sender":["5fa6c6d7-077a-4467-9bb3-1f2c2ee58d78","5e7b8786-4885-4e2d-b4c6-98dc21856ba9","3444aadc-ed01-4ce6-94bc-ae144510eb31","41dl-Gj3"],"timestamp":1440885632.49,"msg_id":"5fa6c6d7-077a-4467-9bb3-1f2c2ee58d78.147","payload":{"IoMessage":{"pin_name":"green-led","val":true}}}
These steps are followed while implementing C# port of this library:
-
Create an application that can send and receive strings (eg. 'Hello' and 'Hello back!') via ZeroMQ .
-
Install aktos-dcs.
-
Edit and set
DEBUG_NETWORK_MESSAGES = True
inaktos_dcs/gevent_actor.py
file to see the debug messages. -
Run
examples/ponger.py
. -
Send following string (
the_raw_msg
) as is from the new implementation code and see ifbroker got message
message is printed inponger.py
:"{ \"timestamp\": 1451168495.814, \"msg_id\": \"MZ9YV.6\", \"sender\": [\"MZ9YV\", \"cKsNg\"], \"payload\": {\"PongMessage\": {\"text\": \"Hello ponger, this is pinger 1!\"}}}"
Note that field strings (like
timestamp
ormsg_id
etc...) SHOULD be in double quotes (like"msg_id"
, not single quotes (not like'msg_id'
), else message won't be unpacked byponger.py
.
-
Because
timestamp
is too old, message will be dropped. See the following message:dropping timeouted message (XXXXX seconds old.) filter process done...
-
Update
timestamp
field with a current unix time value.Note that if you see "key name of object must be string" error, you should check the timestamp value if its decimal separator is dot(
.
), not comma (,
). -
See that messages are not dropped because of they are too old, but they are dropped because they are duplicates.
-
Append a sequence number to
msg_id
field value. -
See messages are reaching
ponger.py
correctly. -
Listen for
ponger.py
's answers. -
Move the listener (the subscriber) to a different thread (or
BackgroundWorker
). -
Create
msg_id
s andsender
id randomly.