Class: MessageDispatcher

iotcs.device.util.MessageDispatcher(dcdUtil)

new MessageDispatcher(dcdUtil)

This object is used for store and forward messages to the cloud by using a priority queue and handling the priority attribute of messages. It is also used for monitoring received messages and any errors that can arise when sending messages.

There can be only one MessageDispatcher instance per DirectlyConnectedDevice at a time and it is created at first use. To close an instance of a MessageDispatcher the DirectlyConnectedDevice.close method must be used.

The message dispatcher uses the RequestDispatcher for dispatching automatically request messages that come from the server and generate response messages to the server.

The onDelivery and onError attributes can be used to set handlers that are called when messages are successfully delivered or an error occurs:
messageDispatcher.onDelivery = function (messages);
messageDispatcher.onError = function (messages, error);
Where messages is an array of the iotcs.message.Message object representing the messages that were sent or not and error is an Error object.

Also the MessageDispatcher implements the message dispatcher, diagnostics and connectivity test capabilities.

Parameters:
Name Type Description
dcdUtil iotcs.device.util.DirectlyConnectedDevice The directly connected device (Messaging API) associated with this message dispatcher.
See:

Members

(nullable) onDeliveryCallback :iotcs.device.util.MessageDispatcher~onDeliveryCallback

(Optional) Callback function called when messages are successfully delivered to the IoT CS.
Type:

Methods

(static) getRequestDispatcher() → {iotcs.device.util.RequestDispatcher}

This method returns the RequestDispatcher used by this MessageDispatcher for dispatching messages.
Returns:
The RequestDispatcher instance.
Type
iotcs.device.util.RequestDispatcher

(static) offer(message)

Offer a message to be queued. Depending on the policies, if any, the message will be queued if it is possible to do so without violating capacity restrictions.
Parameters:
Name Type Description
message iotcs.message.Message The message to be offered.
Throws:
  • Error if all the messages cannot be added to the queue.
  • Error if messages is null or empty.

Type Definitions

onDeliveryCallback(An)

Callback function called when messages are successfully delivered to the IoT CS.
Parameters:
Name Type Description
An Array.<iotcs.message.Message> array of the iotcs.message.Message's representing the messages that were sent.

Home