> ## Documentation Index
> Fetch the complete documentation index at: https://docs.coreflux.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Azure Event Hubs

> Client-mode REST API connector for Azure Event Hubs runtime send: single event, partition-key event, explicit partition, and batch events over HTTPS with SAS or Entra ID

Technical Preview

## Overview

A client-mode connector that forwards broker data into [Azure Event Hubs](https://learn.microsoft.com/en-us/azure/event-hubs/event-hubs-about) over the runtime REST send API. Use it to stream plant telemetry into Azure analytics (Stream Analytics, Fabric Real-Time Intelligence, Data Explorer, Databricks) without running an AMQP or Kafka client.

| Event | Request | Notes |
| - | - | - |
| SendEvent | `POST /{hub}/messages` | One event; `application/atom+xml;type=entry;charset=utf-8` |
| SendEventWithPartitionKey | `POST /{hub}/messages` + `BrokerProperties` | Same key lands on the same partition (ordered per device) |
| SendPartitionEvent | `POST /{hub}/partitions/{id}/messages` | Explicit partition |
| SendBatch | `POST /{hub}/messages` | JSON array of `{"Body", "UserProperties"}`; `application/vnd.microsoft.servicebus.json` |

Every request uses `api-version=2014-01` and returns **201 Created** with an empty body. Default `BASE_ADDRESS` is `https://YOUR_NAMESPACE.servicebus.windows.net` (no trailing slash). Topics use `data/azure-event-hubs/<object>/<verb>`.

See the base guide: [REST API Connectors](/latest/lot-language/routes/rest-api-routes).

> [!NOTE]
>
> **Auth:** pass the full `Authorization` value as `{value.json.authorization}`, either `SharedAccessSignature sr=…&sig=…&se=…&skn=…` from a policy with the **Send** claim, or `Bearer {entra_token}` (scope `https://eventhubs.azure.net/.default`, role **Azure Event Hubs Data Sender**). Prefer Hub secrets; never commit keys into the `.lot`.

> [!NOTE]
>
> **Send only.** Event Hubs has no REST receive API; consumers use AMQP or Kafka. The management plane (creating namespaces and hubs) goes through Azure Resource Manager and is not packaged. A **Fabric Eventstream** custom endpoint exposes an Event Hubs-compatible namespace and SAS key, so the same template applies. This template has not yet been verified against a live namespace.

## Basic Syntax

```lot wrap theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
DEFINE ROUTE AzureEventHubsRestApi WITH TYPE REST_API
    ADD REST_API_CONFIG
        WITH BASE_ADDRESS "https://YOUR_NAMESPACE.servicebus.windows.net"
        WITH ENABLE_CLIENT "true"
        WITH USE_SSL "true"
        WITH REQUEST_TIMEOUT '60'
        WITH DEFAULT_CONTENT_TYPE "application/json"
        # Auth: SAS or Entra Bearer via {value.json.authorization} (see header comments). Never commit real keys.
    ADD EVENT SendEvent
        WITH SOURCE_TOPIC "data/azure-event-hubs/messages/post"
        WITH DESTINATION_TOPIC "data/azure-event-hubs/messages/post/response"
        WITH METHOD "POST"
        WITH ENDPOINT "/{value.json.hub}/messages?timeout=60&api-version=2014-01"
        WITH HEADERS
            ADD "Content-Type" "application/atom+xml;type=entry;charset=utf-8"
            ADD "Authorization" "{value.json.authorization}"
        WITH BODY "{value.json.body}"
    ADD EVENT SendEventWithPartitionKey
        WITH SOURCE_TOPIC "data/azure-event-hubs/messages/keyed/post"
        WITH DESTINATION_TOPIC "data/azure-event-hubs/messages/keyed/post/response"
        WITH METHOD "POST"
        WITH ENDPOINT "/{value.json.hub}/messages?timeout=60&api-version=2014-01"
        WITH HEADERS
            ADD "Content-Type" "application/atom+xml;type=entry;charset=utf-8"
            ADD "Authorization" "{value.json.authorization}"
            ADD "BrokerProperties" "{value.json.broker_properties}"
        WITH BODY "{value.json.body}"
    ADD EVENT SendPartitionEvent
        WITH SOURCE_TOPIC "data/azure-event-hubs/partitions/messages/post"
        WITH DESTINATION_TOPIC "data/azure-event-hubs/partitions/messages/post/response"
        WITH METHOD "POST"
        WITH ENDPOINT "/{value.json.hub}/partitions/{value.json.partition_id}/messages?timeout=60&api-version=2014-01"
        WITH HEADERS
            ADD "Content-Type" "application/atom+xml;type=entry;charset=utf-8"
            ADD "Authorization" "{value.json.authorization}"
        WITH BODY "{value.json.body}"
    ADD EVENT SendBatch
        WITH SOURCE_TOPIC "data/azure-event-hubs/messages/batch/post"
        WITH DESTINATION_TOPIC "data/azure-event-hubs/messages/batch/post/response"
        WITH METHOD "POST"
        WITH ENDPOINT "/{value.json.hub}/messages?timeout=60&api-version=2014-01"
        WITH HEADERS
            ADD "Content-Type" "application/vnd.microsoft.servicebus.json"
            ADD "Authorization" "{value.json.authorization}"
        WITH BODY "{value.json.body}"
```

## MQTT examples

**SendEvent** (`data/azure-event-hubs/messages/post`), expect **201 Created** with an empty body:

```json theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
{
  "hub": "press-telemetry",
  "authorization": "SharedAccessSignature sr=https%3A%2F%2FYOUR_NAMESPACE.servicebus.windows.net%2Fpress-telemetry&sig=...&se=1767225600&skn=coreflux-send",
  "body": {
    "DeviceId": "press-01",
    "Temperature": 37.0,
    "ts": "2026-10-05T00:21:00Z"
  }
}
```

**SendEventWithPartitionKey** (`data/azure-event-hubs/messages/keyed/post`), expect **201 Created** with an empty body:

```json theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
{
  "hub": "press-telemetry",
  "authorization": "SharedAccessSignature sr=...&sig=...&se=...&skn=coreflux-send",
  "broker_properties": "{\"PartitionKey\":\"press-01\"}",
  "body": {
    "DeviceId": "press-01",
    "rpm": 1450
  }
}
```

**SendPartitionEvent** (`data/azure-event-hubs/partitions/messages/post`), expect **201 Created** with an empty body:

```json theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
{
  "hub": "press-telemetry",
  "partition_id": "0",
  "authorization": "SharedAccessSignature sr=...&sig=...&se=...&skn=coreflux-send",
  "body": {
    "DeviceId": "press-02",
    "state": "RUN"
  }
}
```

**SendBatch** (`data/azure-event-hubs/messages/batch/post`), expect **201 Created** with an empty body:

```json theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
{
  "hub": "press-telemetry",
  "authorization": "Bearer <entra_access_token>",
  "body": [
    {
      "Body": "{\"DeviceId\":\"press-01\",\"t\":37.1}",
      "UserProperties": {
        "line": "A"
      }
    },
    {
      "Body": "{\"DeviceId\":\"press-02\",\"t\":36.8}"
    }
  ]
}
```

`body` becomes the HTTP body, so control fields (`hub`, `authorization`, `partition_id`, `broker_properties`) are never sent to Azure.

## Generating a SAS token

The signature is `HMAC-SHA256(key, url_encode(resource_uri) + "\n" + expiry)`, base64-encoded and URL-encoded. With Azure CLI you can read the policy key:

```bash theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
az eventhubs eventhub authorization-rule keys list -g YOUR_RG --namespace-name YOUR_NAMESPACE --eventhub-name press-telemetry -n coreflux-send
```

Then build the token with the snippet from [Generate SAS token](https://learn.microsoft.com/en-us/rest/api/eventhub/generate-sas-token). Keep expiry short and rotate through Hub secrets.

## Notes

* Replace `YOUR_NAMESPACE` in `BASE_ADDRESS` before deploy.
* Max event or batch size is 1 MB (Standard and above); 256 KB on Basic.
* `UserProperties` in headers are ignored for batches; put them inside each batch item.
* Suggested branches: `feat/rest-api-route-azure-event-hubs`, `feat/docs-rest-api-azure-event-hubs` (Hugo pushes).

## Related

* [REST API Connectors](/latest/lot-language/routes/rest-api-routes)
* [Send event](https://learn.microsoft.com/en-us/rest/api/eventhub/send-event)
* [Send batch events](https://learn.microsoft.com/en-us/rest/api/eventhub/send-batch-events)
* [Send partition event](https://learn.microsoft.com/en-us/rest/api/eventhub/send-partition-event)
* [Authenticate with SAS](https://learn.microsoft.com/en-us/azure/event-hubs/authenticate-shared-access-signature)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.