topic structure

87 views
Skip to first unread message

Toby Dickenson

unread,
Mar 25, 2014, 3:37:46 PM3/25/14
to mq...@googlegroups.com
Hi,

I'm looking for some advice or examples on best practice for topic structure. In particular, I dont have any intuition about how much information to pack into one message.

For example, if we were considering some messages:
/sensor/<id>/temperature/value 21.2
/sensor/<id>/temperature/timestamp 2014-03-25 19:28:51

Would it be better to combine that all into one message:
/sensor/<id>/temperature 2014-03-25 19:28:51, 21.2

That has the advantage of atomicity (no chance of a client seeing a new value with the old timestamp), at the expense of needing a little parser for a format that might not be quite so universal.

Thanks in advance,

Nicholas O'Leary

unread,
Mar 25, 2014, 6:52:44 PM3/25/14
to mq...@googlegroups.com
Hi Toby,

you are much better off publishing a single message with all of the data for that event in it. Trying to split a single 'event' into multiple messages published to multiple topics will give you a headache when it comes to correlating the messages back into a single event.

Nick


--
To learn more about MQTT please visit http://mqtt.org
---
You received this message because you are subscribed to the Google Groups "MQ Telemetry Transport" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mqtt+uns...@googlegroups.com.
To post to this group, send email to mq...@googlegroups.com.
Visit this group at http://groups.google.com/group/mqtt.
For more options, visit https://groups.google.com/d/optout.

Dominik Obermaier

unread,
Mar 26, 2014, 4:11:46 AM3/26/14
to mq...@googlegroups.com
Hi Toby,

I think there is no golden rule how to do this, I personally am in strong favor of the "one message with all data". You probably have to write your own parser for the payload anyway.

If you are worried about writing your own parsers or if you are worried about the added overhead of too much data in the payload, you could use Protobuf or Msgpack for the payload.


Toby Dickenson wrote:

Darren Clark

unread,
Mar 26, 2014, 5:04:45 AM3/26/14
to mq...@googlegroups.com

I use JSON myself. Although I don't have to worry about bandwidth so much. Still reasonably compact. Every message has two properties, time, which is a local timestamp, and value, that is a JSON object.

-D

Nicholas O'Leary

unread,
Mar 26, 2014, 5:06:24 AM3/26/14
to mq...@googlegroups.com
Sometimes simple csv is all you need.

Tomoaki Yamaguchi

unread,
Mar 26, 2014, 9:21:38 AM3/26/14
to mq...@googlegroups.com
I use the binary data structure as follows:   When, Where and Value

struct measurementData{
    uint32_t      utc
    int32_t        latitude     
    int32_t        longitude
    int16_t        altitude
    uint8_t        valueType     //  1:fValue, 2: lValue, 3: iValue
    union          value{
             float      fValue
             long      lValue
             int          iValue
       }
}
               Tomoaki  YAMAGUCHI

vat...@litmusautomation.com

unread,
Mar 26, 2014, 4:13:14 PM3/26/14
to mq...@googlegroups.com
I prefer single topic with JSON { ID, Value, timestamp }
It keeps your data organized.
Reply all
Reply to author
Forward
0 new messages