Skip to content

Cookie preferences

We use cookies for our own analytics, to see how our campaigns perform and, if you allow it, to load content from other services such as the Google site search. We never sell your data. Necessary cookies keep the site working and cannot be switched off. See our Cookie Policy for details and our Privacy Policy for how we handle personal data.

Security, load balancing and remembering your cookie choice.

Show us which pages people read, how they find the site and where they get stuck, so we can improve it (Google Analytics, Microsoft Clarity).

Show us which of our ad campaigns bring visitors to the site and remember the campaign or partner link you arrived from (Google Ads, LinkedIn, Meta, partner program). We do not use these cookies to build advertising profiles.

Load the site search from Google when you use it. Google sets its own cookies and shows ads in the search results.

© 2026 The ThingsBoard Authors

Azure Service Bus Integration

Azure Service Bus Integration receives messages from a topic subscription in Azure Service Bus. An uplink data converter transforms each message into device or asset data, including telemetry and attributes. ThingsBoard can also publish downlink messages to a separate Service Bus topic.

Use Azure Service Bus Integration when:

  • Your applications or IoT platforms already publish device data to a Service Bus topic.
  • Several consumers must read the same data: each topic subscription receives its own copy of every message.
  • Backend services must receive commands or data from ThingsBoard through a Service Bus topic.
  1. Receive data. A producer sends a message to the uplink topic. The integration receives it from its subscription on that topic.
  2. Decode the payload. The uplink converter identifies the target device or asset from the payload or the message’s custom properties, and extracts attributes and telemetry.
  3. Process the message. ThingsBoard processes the converted data through the Rule Engine. If Allow create devices or assets is enabled, ThingsBoard can create an entity that does not exist yet.
  4. Send downlink data (optional). The Rule Engine passes a message to the integration. The downlink converter encodes it, and the integration publishes it to the downlink topic.
  • Access to ThingsBoard or ThingsBoard Cloud with integrations enabled for your tenant.
  • Permission to create integrations and data converters, and to edit rule chains for downlink.
  • An Azure account with an active subscription and permission to create a Service Bus namespace on the Standard or Premium tier. The Basic tier does not support topics.
  • Outbound TCP port 5671 (AMQP) open from the ThingsBoard server (or the remote integration host) to *.servicebus.windows.net.

Create a namespace, a topic with a subscription for ThingsBoard, and a policy that ThingsBoard uses to read the messages. For details, see Create Service Bus topics and subscriptions.

  1. In the Azure portal, search for Service Bus, open it, and click + Create.
  2. On the Basics tab, select or create a Resource group, for example tb-integrations, enter a globally unique Namespace name, for example tb-servicebus-01, and choose a Location.
  3. Set Pricing tier to Standard or Premium. The Basic tier does not support topics.
  4. Click Review + create, then Create.
  5. When the deployment finishes, click Go to resource.

The integration reads messages from a subscription on a topic, not from a queue. Each subscription receives its own copy of every message sent to the topic, so give ThingsBoard a subscription that no other application reads.

  1. In the namespace, go to Entities ⇾ Topics and click + Topic.
  2. Enter a Name, for example tb-uplink, keep the other settings, and click Create.
  3. Open the topic, go to Entities ⇾ Subscriptions, and click + Subscription.
  4. Enter a Name, for example thingsboard, keep Max delivery count 10 and the other settings, and click Create.

Downlink uses a second topic. You create it in Configure Downlink.

ThingsBoard needs only Listen permission to receive messages. Create a separate policy for it, so the key does not allow sending or managing the namespace.

  1. In the namespace, go to Settings ⇾ Shared access policies and click + Add.
  2. Enter a Policy name, for example tb-listen, select Listen, and click Create.
  3. Open the policy and copy the Primary connection string. It has the form Endpoint=sb://tb-servicebus-01.servicebus.windows.net/;SharedAccessKeyName=tb-listen;SharedAccessKey=<key>.

You now have the values for the integration:

Value Example Source
Connection string Endpoint=sb://tb-servicebus-01.servicebus.windows.net/;SharedAccessKeyName=tb-listen;SharedAccessKey=… Primary connection string of the policy
Topic name tb-uplink The topic
Subscription name thingsboard The subscription on the topic

Create the uplink converter, assign it to a new Azure Service Bus integration, and send a test message.

The uplink converter receives each message body as a byte array, finds the target device, and returns its telemetry and attributes. For converter types and the full decoder reference, see Uplink data converter.

  1. Go to Integrations ⇾ Data converters and click + Add data converter ⇾ Create new converter.

  2. Converter type — keep Uplink.

  3. Integration type — select Azure Service Bus.

  4. Name — enter a name, for example Azure Service Bus Uplink Converter.

  5. Main decoding configuration — the editor opens with the default Azure Service Bus template, which is the decoder below. Keep it, or adapt it to your payload. The editor opens in TBEL; use the TBEL / JS toggle to switch to JavaScript.

    /** Decoder **/
    // Decode the incoming payload to a JSON object.
    var data = decodeToJson(payload);
    // The device name comes from deviceId in the payload.
    // Otherwise, it comes from the custom message property deviceId (sysProp:deviceId).
    // Reject the message if neither is present.
    var deviceName = data.deviceId != null ? data.deviceId.toString().trim() : "";
    var propertyId = metadata["sysProp:deviceId"];
    if (deviceName.isEmpty() && propertyId != null) {
    deviceName = propertyId.trim();
    }
    if (deviceName.isEmpty()) {
    raiseError("Payload has no deviceId and the message has no deviceId property");

    The decoder:

    • takes the device name from deviceId in the payload, or from the custom message property deviceId, and rejects the message if both are missing;
    • takes the device profile from deviceType, or uses default;
    • uses timestamp as the time of the data, or the server time if the payload has no timestamp;
    • stores location and metadata.version / metadata.manufacturer as attributes, and all other fields as telemetry.

    To adapt:

    • Device name in another field — replace data.deviceId, for example with data.serialNumber.
    • Fields that are not telemetry — add them to handled, then map them yourself.
    • Update-only keys — for Azure Service Bus, ThingsBoard pre-fills the Update only keys list in Advanced decoding parameters with manufacturer, receivedAlarms, status, batteryLevel, batteryStatus, and version. These keys are stored only when their value changes. Edit the list to match your keys.
  6. Click Test decoder function and check the result (see Test the Decoder).

  7. Click Add.

Decoder Inputs

The decoder signature is function decoder(payload, metadata): object | object[].

Variable Type Content
payload byte array The message body.
metadata {[key: string]: string} integrationName, the key–value pairs from the integration’s Metadata field, and each custom property of the message as sysProp:<name>, for example sysProp:site. Broker properties such as Label/Subject or Message ID are not passed.

Built-in helpers:

Function Result
decodeToJson(payload) Parses the bytes as JSON and returns an object.
decodeToString(payload) Converts the bytes to a UTF-8 string.

For field renaming, nested values, and non-JSON payloads, see Common scripting patterns.

Test the Decoder

Click Test decoder function below the editor. Metadata holds integrationName, and Payload already holds a sample message, the same one that you send in Test Uplink:

{"deviceId": "sb-sensor-01", "temperature": 24.6, "humidity": 51}

Click Test. The Output panel shows:

{
"deviceName": "sb-sensor-01",
"deviceType": "default",
"attributes": {},
"telemetry": {
"ts": 1795099761202,
"values": {
"temperature": 24.6,
"humidity": 51
}
}
}

The payload has no timestamp, so ts is the time of the test, in milliseconds, and differs in your output. Neither temperature nor humidity is named in the decoder: like every other top-level field that is not in handled, they become telemetry as they are.

Check that deviceName is set and telemetry holds the expected keys. If the output is empty or shows an error, fix the decoder and test again.

  1. Go to Integrations ⇾ Integrations and click + Add integration.
  2. Basic settings:
    • Integration type — select Azure Service Bus.
    • Name — keep the default Azure Service Bus integration or enter your own.
    • Enable integration and Allow create devices or assets — keep both on, so the device is created on its first uplink.
    • Click Next.
  3. Uplink data converter:
    • Click Select existing and choose Azure Service Bus Uplink Converter.
    • Click Next.
  4. Downlink data converter:
  5. Connection:
    • Connection string — paste the Primary connection string of tb-listen.
    • Topic name — enter tb-uplink.
    • Subscription name — enter thingsboard.
    • See Connection Settings for details.
  6. Click Add.
Parameter Description
Connection string Connection string of a policy with Listen permission. Required.
Topic name Topic the integration receives from. Required.
Subscription name Subscription on that topic. Required.
Downlink connection string Connection string of a policy with Send permission. Shown and required only when a downlink converter is assigned.
Downlink topic name Topic the integration publishes downlinks to. Shown and required only when a downlink converter is assigned.
Execute remotely Runs the integration as a separate process outside the ThingsBoard cluster, for example in a network with access to Azure. ThingsBoard generates an Integration key and Integration secret for it. See Remote Integration.

Advanced settings

Parameter Description
Description Free-text description.
Metadata Key–value pairs added to the metadata of every message from this integration.

Check connection reads only the connection string and does not connect to Service Bus. It shows Connection established. even for a wrong key or a topic that does not exist, so check the names and the key against the Azure portal.

If the converter fails on a message, the integration still removes the message from the subscription, and the message is lost. Check Error events of the converter to catch such messages.

Send a message to tb-uplink, then confirm that ThingsBoard decoded it and created the device.

  1. In the namespace, go to Entities ⇾ Topics and open tb-uplink.

  2. Click Service Bus Explorer in the topic menu, then click Send messages.

  3. Set Content type to application/json.

  4. Paste the payload into Message Body:

    {"deviceId": "sb-sensor-01", "temperature": 24.6, "humidity": 51}
  5. Click Send.

The payload has no timestamp, so the decoder uses the server time.

To add a custom property, expand Custom Properties in the Send messages panel. The decoder receives it as sysProp:<name>.

  • Integration events — go to Integrations ⇾ Integrations, open the integration, and click the Events tab. The uplink appears with status OK. Click ⋅⋅⋅ in the Message column to see systemProperties (the custom properties of the message) and payload.
  • Converter events — open Azure Service Bus Uplink Converter in Integrations ⇾ Data converters and click the Events tab. In shows the received payload, Out shows the decoded result, and Metadata shows integrationName and any sysProp: values.
  • Device — go to Devices & assets ⇾ Devices. The integration has created sb-sensor-01 with the default profile. Open it and check the Latest telemetry tab for temperature 24.6 and humidity 51.

ThingsBoard publishes a downlink when the Rule Engine routes a message to the integration — for example, after a shared attribute update. The integration sends it to the Downlink topic name. Every subscription on that topic receives a copy, and your backend reads it from its subscription.

Each downlink message carries:

  • Body — the encoder’s data.
  • contentType — the encoder’s contentType: JSON, TEXT, or BINARY.
  • to — the encoder’s metadata.deviceId.
  • Custom properties — every key of the encoder’s metadata.

The downlink converter turns a Rule Engine message into the published message. For the full encoder reference, see Downlink data converter.

A message sent to a topic without subscriptions is discarded, so the downlink topic needs a subscription for its consumer before ThingsBoard publishes to it.

  1. In the namespace, go to Entities ⇾ Topics, click + Topic, enter tb-downlink, and click Create.
  2. Open tb-downlink, go to Entities ⇾ Subscriptions, click + Subscription, enter device-commands, keep Max delivery count 10, and click Create. Your backend reads the downlinks from this subscription.
  3. In the namespace, go to Settings ⇾ Shared access policies, click + Add, enter tb-send, select Send, and click Create.
  4. Open tb-send and copy the Primary connection string.

The encoder must set metadata.deviceId. Without it, the integration skips the message without an error.

  1. Open the integration in Integrations ⇾ Integrations and click Toggle edit mode (pencil icon).
  2. In the Downlink data converter field, click Create new. The Downlink converter type and Azure Service Bus integration type are preselected.
  3. Enter a name, for example Azure Service Bus Downlink Converter.
  4. Click the debug button next to the name, select All messages, and click Apply. A converter created here records only failures, so without this its Events tab shows only errors.
  5. Main encoding configuration opens with the default Azure Service Bus encoder, which is the encoder below. Keep it, or adapt it.
  6. Click Add.
  7. Below Subscription name, fill in the fields that appear once the downlink converter is assigned:
    • Downlink connection string — the Primary connection string of tb-send.
    • Downlink topic name — enter tb-downlink.
  8. Click Apply changes.
/** Encoder **/
// Publish the ThingsBoard message as JSON to the downlink topic.
// metadata.deviceId becomes the To property and the custom property deviceId of the message;
// the integration skips messages without it. This template uses the ThingsBoard device name.
// Add it to the message metadata with the "originator fields" rule node (Name -> deviceName).
var deviceId = metadata.deviceName != null ? metadata.deviceName.trim() : null;
if (deviceId == null || deviceId.isEmpty()) {
raiseError("Message metadata has no deviceName");
}
var result = {
// Payload content type: JSON, TEXT, or BINARY (Base64).
contentType: "JSON",
data: JSON.stringify(msg),

To check the encoder, click Test encoder function. Message type (ATTRIBUTES_UPDATED), Message ({"temperatureUploadFrequency": 60}), and deviceName sb-sensor-01 in Metadata are already filled in. Click Test. The Output shows:

{
"contentType": "JSON",
"data": "{\"temperatureUploadFrequency\":60}",
"metadata": {
"deviceId": "sb-sensor-01"
}
}

To adapt:

  • Another envelope — build data in the structure your consumer expects, for example { "device": deviceId, "config": msg }.
  • Routing properties — add keys to metadata, for example type: "config". Subscription filter rules on the downlink topic can route on these custom properties.
  • Other message types — branch on msgType, for example to handle RPC_CALL_FROM_SERVER_TO_DEVICE with msg.method and msg.params. See Rule Engine message types.

The encoder reads deviceName from the message metadata, so the rule chain first adds the device name.

  1. Go to Data processing ⇾ Rule chains and open the Root Rule Chain.
  2. From the Enrichment section, drag an originator fields node onto the canvas.
  3. Enter a Name, for example Add device name, and map the source fields:
    • Name ⇾ deviceName
    • Add mapped originator fields to ⇾ Metadata
    • Click Add.
  4. Connect the message type switch node to the originator fields node with the Attributes Updated relation.
  5. From the Action section, drag an integration downlink node onto the canvas.
  6. Enter a Name, for example Downlink to Azure Service Bus, select Azure Service Bus integration, and click Add.
  7. Connect the originator fields node to the integration downlink node with the Success relation.
  8. Click Apply changes.
  1. Go to Devices & assets ⇾ Devices, select sb-sensor-01, and open the Attributes tab.
  2. Select Shared attributes and click +.
  3. Set Key to temperatureUploadFrequency, Type to Integer, Value to 60, and click Add. ThingsBoard publishes the downlink.
  • Integration events — the integration’s Events tab shows a Downlink event with deviceId sb-sensor-01, payload {"temperatureUploadFrequency":60}, and properties.
  • Service Bus Explorer — open tb-downlink, click Service Bus Explorer, select the subscription device-commands, and click Peek from start. Select the message: Message Body shows {"temperatureUploadFrequency":60}; Message Properties shows contentType JSON, to sb-sensor-01, and the custom property deviceId sb-sensor-01.

Peek from start leaves the message in the subscription.

Symptom Cause Fix
Check connection shows Connection established., but no uplinks arrive Check connection does not connect to Service Bus. The namespace, topic, subscription, or key is wrong, or the policy lacks Listen. Compare the names with the Azure portal. Copy the connection string again from a policy with Listen.
Uplinks stop, the integration shows no errors The key of the policy was regenerated, or the topic or subscription was deleted. ThingsBoard writes the error only to the server log, for example 401 InvalidSignature. After a key change, copy the new connection string to the integration and click Apply changes; the messages that waited in the subscription arrive. If the topic or subscription was deleted, create it again; messages sent while it was missing are not delivered.
Same, from a private network Outbound port 5671 is blocked. Open TCP 5671 to *.servicebus.windows.net, or use a Remote Integration.
Messages go to another consumer Another application reads the same subscription. Create a dedicated subscription for ThingsBoard.
Topics are not available The namespace is on the Basic tier. Use the Standard or Premium tier.
Uplink event with status ERROR The converter failed on the message. The message is removed from the subscription and lost. Check Error in the converter events, fix the decoder, and send the message again.
Device not created deviceName is empty, or Allow create devices or assets is off. Check Out in the converter events and the integration settings.
Downlink: ATTRIBUTES_UPDATED is OK, but no Downlink event and nothing in the downlink subscription The encoder does not set metadata.deviceId, so the integration skips the message. Check Out in the downlink converter events for deviceId. Use the encoder from this guide.
No downlink events at all The rule chain does not reach the integration downlink node. Check the Root Rule Chain wiring.
Downlink event with status ERROR The encoder found no deviceName in the message metadata, or the Downlink connection string, Downlink topic name, or Send permission is wrong. Read the error text in the event. Check the originator fields node in the Root Rule Chain, and compare the downlink settings with tb-send and tb-downlink in the Azure portal.
Downlink event is OK, nothing in the downlink subscription The downlink topic had no subscription when the message arrived, or a subscription filter rejected it. Create the subscription before you trigger the downlink. Check its filter rules.

To read debug events, open the integration or converter, click Events, and select an event: In is the received data, Out is the converter result, and Error holds the error text.