Skip to main content

Using the nRF Cloud Message Routing Service

This guide explains how to use the nRF Cloud Message Routing Service through the nRF Cloud portal and APIs.

Prerequisites

  • Create an nRF Cloud account.
  • Have an Owner or Admin role in your team.
  • Create a destination with your web service URL. For more information and an example, see Receiving messages from nRF Cloud.
  • Verify your destination. Before your server can start receiving messages from your team, it must be verified. See Verification for details.
  • Add one or more devices to your team.

Using the nRF Cloud portal

This section explains message routing operations available in the nRF Cloud portal.

Managing destinations

You can create, edit, delete, test, enable or disable, and verify destinations in the nRF Cloud portal.

After you have an HTTP server that can receive requests from nRF Cloud, finish setting up message routing by creating a new destination:

  1. Log in to the nRF Cloud portal.

  2. Select Device Management from the left sidebar.

    A panel opens to the right.

  3. Select Message Routing Service.

  4. Click the Add Destination button.

    A pop-up opens.

  5. Enter the name of the destination and URL.

  6. (Optional) Enter additional information:

    • Contact email address: You need this if you want to receive email alerts when your DLQ has more than 20 messages in it.
    • Filter Categories: Configure message filtering to control which types of messages are forwarded to your destination. See Message Filtering for details.
    • Token: Provide this if your own service requires it, or as a convenient way to identify messages from nRF Cloud. Adds x-api-key to requests with your token value.
    • Secret: Used for identity verification. Adds x-nrfcloud-signature to requests.
    • Verify Server Socket Layer toggle: Leave this as-is, unless you want to disable SSL.
    • Is Enabled toggle: Leave this on if you want the destination to be enabled on creation.
  7. Click the Create Destination button.

Using the nRF Cloud APIs

This section explains message routing operations through the nRF Cloud APIs.

Managing destinations

See the Message Routing Service API documentation for more information on specific endpoint requirements.

Call the CreateDestination endpoint to create a new destination.

Example request body:

{
"name": "Test Webhook",
"config": {
"type": "http",
"url": "https://example.com/webhook-endpoint",
"verifySsl": true
},
"dlqNotificationEmails": [
"user1@example.com",
"user2@example.com",
],
"isEnabled": true
}

The server responds with HTTP 201 and information about the newly created destination:

{
"id": "5b5d8b40-e251-41bc-a45c-f932c603f121",
"createdAt": "2024-08-07T03:38:15.040913Z",
"name": "Test Webhook",
"config": {
"type": "http",
"url": "https://example.com/webhook-endpoint",
"verifySsl": true
},
"isEnabled": true,
"errors": [],
"dlqSize": 0,
"dlqNotificationEmails": ["user1@example.com","user2@example.com"]
}

Message filtering

You can optionally configure message filtering for your destinations to control which types of messages are forwarded to your destination.

Pre-defined filtering categories

The following pre-defined filtering categories are available:

  • location: Location-related messages (AGNSS, AGPS, PGPS, Ground fix, cell positioning, Wi-Fi positioning)
  • shadow: Device shadow messages (shadow updates, state changes)
  • fota: Firmware over-the-air update messages
  • device_messages: Device-to-Cloud messages (including binary and raw data)
  • cloud_messages: Cloud-to-Device messages

Configuring message filters

You can configure message filtering through both the nRF Cloud portal and the APIs.

Through the nRF Cloud portal

When creating or editing a destination in the portal:

  1. In the destination configuration form, locate the Filter Categories field.
  2. Select the categories you want to forward to this destination.
  3. Only messages matching the selected categories will be sent to your endpoint.
  4. If no filters are specified, all message types will be forwarded (default behavior).

Through the APIs

When using the CreateDestination or UpdateDestination endpoint, include a filter object in your destination configuration:

{
"name": "My Filtered Destination",
"config": {
"type": "http",
"url": "https://example.com/webhook",
"verifySsl": true
},
"filter": {
"categories": ["location", "shadow"]
},
"isEnabled": true
}

Examples

  • To receive only location and shadow messages: ["location", "shadow"]
  • To receive only device messages: ["device_messages"]
  • To receive all messages (default), clear the filter object.

Using the dead letter queue

If a message cannot be routed to its destination, delivery will be retried for up to 24 hours. If the message still cannot be delivered after this period, it will be moved to the dead letter queue (DLQ).

To view the failed messages in the DLQ, you can use the ListDLQItems endpoint.

nRF Cloud checks the DLQ once a day. If the DLQ contains more than 20 failed messages at the time of the check, a notification email is sent to the DLQ notification email address for that destination, if you have provided one.

Messages remain in the DLQ for up to 30 days, after which they are deleted automatically. You can also manually clear the DLQ at any time.

Viewing and managing the DLQ through the APIs

This section explains how to view and clear the DLQ.

Call the ListDlqItems endpoint to view messages in the DLQ.

The server responds with HTTP 200 and a list of messages in the DLQ.

Example response:

{
"items": [
{
"teamId": "a5592ec1-18ae-4d9d-bc44-1d9bd927bbe9",
"destinationId": "a5592ec1-18ae-4d9d-bc44-1d9bd927bbe9",
"deviceId": "string",
"messageId": "a5592ec1-18ae-4d9d-bc44-1d9bd927bbe9",
"topic": "string",
"message": {
"temperature": 25
},
"receivedAt": 0,
"createdAt": 0
}
],
"total": 10,
"pageNextToken": "4bb1f9ab35bd"
}