About Two-Way Messaging

About Two-Way Messaging

The most common use of the Device Messaging API is for devices to send data and for applications to retrieve the data, which is one-way messaging. Each device that sends messages has a unique name that is known to the application, and the application uses those names to retrieve the messages. For example, monitoring devices for tanks of liquid might send a message every hour with the current temperature and the current liquid level in the tank, and an application could retrieve that data and display a chart, or send an alert if a temperature gets too high or a level gets too low.

If you need to do two-way messaging so that your application can send messages to your devices, you must create the sending-and-retrieving arrangement in reverse, but there are certain caveats to think about:

  • The API uses a publish-subscribe model, so messages are available to any device that wants to retrieve them. Messages are not sent “to” a particular device.
  • Your application must have a thing name in order to send messages. If you want to send messages for individual devices, then your application will need to have a unique thing name for each device to subscribe to. That is, your application will send messages from different names, depending on which device the message is for. See the table below for a simple illustration of this naming scheme.
  • You must run a client on the devices that listens for messages or retrieves messages from your application.
  • The client can be set to get messages sent by more than one name, such as general purpose messages for all devices and specific messages for that unique device.

For example, a simple scenario with two tank monitoring devices and an application might send and receive messages using these names:

Tank or application Sends as Listens for
Tank A Tank A AllTanks-send
TankA-Send
Tank B Tank B AllTanks-send
TankB-Send
Tank Monitor App AllTanks-Send
TankA-Send
TankB-Send
TankA
TankB