new Message()
This object helps in the construction of a general type message to be sent to the server. This
object and it's components are used as utilities by the Messaging API clients, like the
DirectlyConnectedDevice or GatewayDevice or indirectly by the MessageDispatcher.
Classes
Members
(static, constant) BASIC_NUMBER_OF_RETRIES :number
Constant which defines the number of times sending of a message should be retried. The
minimum is 3.
Type:
- number
- Default Value:
- 3
(static, constant) MAX_KEY_LENGTH :number
Type:
- number
- Default Value:
- 2048
(static, constant) MAX_STRING_VALUE_LENGTH :number
Type:
- number
- Default Value:
- 65536
Methods
(static) buildResponseMessage(requestMessageopt, statusCode, headersopt, bodyopt, urlopt) → {iotcs.message.Message}
This is a helper method for building a response message to be sent to the server as response to a
request message sent from the server. This is mostly used by handlers registered with the
RequestDispatcher. If no requestMessage is given the id for the response message will be a
random UUID.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
requestMessage |
object |
<optional> |
The message received from the server as JSON. |
statusCode |
number | The status code to be added in the payload of the response message. | |
headers |
object |
<optional> |
The headers to be added in the payload of the response message. |
body |
string |
<optional> |
The body to be added in the payload of the response message. |
url |
string |
<optional> |
The URL to be added in the payload of the response message. |
Returns:
The response message instance built on the given parameters.
(static) buildResponseWaitMessage() → {iotcs.message.Message}
This is a helper method for building a response wait message to notify RequestDispatcher that
response for server will be sent to the server later. RequestDispatcher doesn't send these kind
of messages to the server. This is mostly used by handlers registered with the
RequestDispatcher in asynchronous cases, for example, when device creates storage object by URI.
- See:
-
iotcs.device.util.RequestDispatcher
iotcs.device.util.DirectlyConnectedDevice#createStorageObject
Returns:
The response message that notified about waiting final response.
(static) checkMessagesBoundaries(messages)
This is a helper method for checking if an array of created messages pass the boundaries on
key/value length test. If the test does not pass an error is thrown.
Parameters:
Name | Type | Description |
---|---|---|
messages |
Array.<iotcs.message.Message> | The array of messages that need to be tested. |
(static) dataItem(dataKey, dataValueopt) → {iotcs.message.Message}
This sets a key/value pair in the data property of the payload of the message. This is
specific to DATA or ALERT type messages.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
dataKey |
string | The key. | |
dataValue |
object |
<optional> |
The value associated with the key. |
Returns:
This object.
(static) destination(destination) → {iotcs.message.Message}
Sets the destination of the message.
Parameters:
Name | Type | Description |
---|---|---|
destination |
string | The destination. |
Returns:
This object.
(static) format(format) → {iotcs.message.Message}
This sets the format URN in the payload of the message. This is mostly specific for the DATA or
ALERT type * of messages.
Parameters:
Name | Type | Description |
---|---|---|
format |
string | The format to set. |
Returns:
This object.
(static) getJSONObject() → {object}
This returns the built message as JSON to be sent to the server as it is.
Returns:
A JSON representation of the message to be sent.
- Type
- object
(static) getRemainingRetries() → {integer}
Gets the number of remaining retries for this message. Not intended for general use. Used
internally by the message dispatcher implementation.
Returns:
remainingRetries - The new number of remaining retries.
- Type
- integer
(static) payload(payload) → {iotcs.message.Message}
Sets the payload of the message as object.
Parameters:
Name | Type | Description |
---|---|---|
payload |
object | The payload to set. |
Returns:
This object
(static) priority(priority) → {iotcs.message.Message}
This sets the priority of the message. Priorities are defined in the Message.Priority
enumeration. If an invalid type is given an exception is thrown. The MessageDispatcher implements
a priority queue and it will use this parameter.
Parameters:
Name | Type | Description |
---|---|---|
priority |
string | The priority to set. |
Returns:
This object.
(static) reliability(priority) → {iotcs.message.Message}
This sets the reliability of the message. Reliabilities are defined in the Message.Reliability
enumeration. If an invalid type is given, an exception is thrown.
Parameters:
Name | Type | Description |
---|---|---|
priority |
string | The reliability to set. |
Returns:
This object.
(static) setRemainingRetries(remainingRetries) → {iotcs.message.Message}
Sets the number of remaining retries for this message. Not intended for general use. Used
internally by the message dispatcher implementation.
Parameters:
Name | Type | Description |
---|---|---|
remainingRetries |
integer | The new number of remaining retries. |
Returns:
This object.
(static) source(source) → {iotcs.message.Message}
Sets the source of the message.
Parameters:
Name | Type | Description |
---|---|---|
source |
string | The source to set. |
Returns:
This object.
(static) type(type) → {iotcs.message.Message}
This sets the type of the message. Types are defined in the
Message.Type enumeration. If an invalid type is given an
exception is thrown.
Parameters:
Name | Type | Description |
---|---|---|
type |
string | The type to set. |
Returns:
This object.