Azure Event Hubs Integration
How to integrate Azure Event Hubs with Connectware, including connecting to the Kafka endpoint of Event Hubs, streaming shop floor data into an event hub, and consuming events from an event hub.
This guide describes how to integrate Azure Event Hubs with Connectware. You configure a service commissioning file that streams shop floor data into an event hub through the Apache Kafka endpoint of Event Hubs and consumes events from an event hub in return. A complete example file is available at the end of this guide.
Objectives
Establishing a connection between Connectware and the Kafka endpoint of Azure Event Hubs.
Streaming shop floor data from MQTT topics into an event hub.
Consuming events from an event hub and publishing them to an MQTT topic.
Verifying the data flow in both directions.
Prerequisites
To follow this guide, you will need the following:
A running instance of Cybus Connectware.
An Azure Event Hubs namespace in the standard, premium, or dedicated tier, with at least one event hub. The basic tier does not support the Kafka endpoint. For more information, see Azure Event Hubs for Apache Kafka in the Azure documentation.
The connection string of your Event Hubs namespace, available under Shared access policies in the Azure portal. For more information, see Get an Event Hubs connection string in the Azure documentation.
Access to the Admin UI with sufficient user permissions.
Basic knowledge of MQTT and the Connectware services concept (for example, service commissioning files, connections, and endpoints).
Connectware and Azure Event Hubs Integration
Azure Event Hubs exposes an Apache Kafka-compatible endpoint on every namespace, reachable at <namespace>.servicebus.windows.net on port 9093. Connectware communicates with this endpoint through the Kafka connector, so no Azure-specific client or SDK is required.
The Kafka concepts map directly to Event Hubs concepts:
Cluster
Namespace
Topic
An event hub
Consumer group
Consumer group
Authentication uses SASL PLAIN over TLS with a shared access signature (SAS): the username is the literal string $ConnectionString, and the password is the connection string of your namespace. When you configure the sasl property, the Kafka connector automatically connects over TLS, which Event Hubs requires for all traffic.
A Kafka connection in Connectware is either a producer or a consumer, controlled by the clientType property. This guide therefore uses two connection resources: one that produces shop floor data into a telemetry event hub, and one that consumes from a commands event hub.
The MQTT topics in this guide follow an ISA-95-style equipment hierarchy (<enterprise>/<site>/<area>/<line>/<cell>). The mapping subscribes with wildcards across all levels, so any machine in the hierarchy is picked up without changing the integration.
This guide covers streaming data into Event Hubs as the entry point to Azure analytics services such as Stream Analytics, Fabric, or Databricks. If you want to connect Connectware as a device to Azure IoT Hub instead, see Azure IoT Hub Integration.
Azure Event Hubs Connection Properties
The connection to Event Hubs requires values from your Azure subscription. We add them as parameters to the service commissioning file, so you can set them when you install the service.
Do not worry about copying the service commissioning file snippets together into one, the complete example file is available at the end of this guide.
eventHubsNamespace: The name of your Event Hubs namespace, without the domain suffix. For example,example-namespaceif your namespace is reachable atexample-namespace.servicebus.windows.net.connectionString: The connection string of your namespace, starting withEndpoint=sb://. A policy with the Send claim is sufficient for producing, the Listen claim is required for consuming.telemetryEventHub: The name of the event hub that receives the shop floor data.commandsEventHub: The name of the event hub that Connectware consumes from.consumerGroupId: The Kafka consumer group ID used when consuming.topicRoot: The root of the MQTT topic hierarchy. Defaults toenterprise.
Kafka Producer Connection
To produce data into Event Hubs, we set up a Cybus::Connection resource that uses the Kafka connector. The broker address is the Kafka endpoint of the namespace on port 9093. The sasl property carries the SAS authentication and enables TLS. For all available properties, see the Kafka connection properties.
The username is not a placeholder. Event Hubs expects the literal string $ConnectionString when authenticating with a connection string.
Streaming Shop Floor Data into an Event Hub
We define a write endpoint whose topic is the name of the event hub, and a mapping that feeds it from the MQTT topic hierarchy. The Kafka connector expects a JSON message with the payload in the value property, and each Kafka message carries its body as a string (see Message assembly). The transform rule serializes the incoming payload with the JSONata $string() function and wraps it accordingly, so machines can publish their data without knowing about this convention.
Any message published to a matching topic, for example enterprise/hamburg/assembly/line-1/press-01/telemetry, now becomes one event in the telemetry event hub:
The result of every write operation is published to the /res topic of the endpoint. On success, the result contains errorCode: 0 and the offset of the produced event.
Leave the compression property of the endpoint at its default None on the standard tier. Event Hubs supports GZIP-compressed Kafka traffic only in the premium and dedicated tiers.
Consuming Events from an Event Hub
For the opposite direction, we set up a second connection with clientType: consumer, a subscribe endpoint for the commands event hub, and a mapping that publishes every consumed event to an MQTT topic, where any other Connectware service can pick it up, for example to write a command to a PLC.
Kafka consumer groups on Event Hubs are created automatically when the consumer connects, so you do not need to create the consumer group in the Azure portal. A Kafka consumer group spans the whole namespace and is separate from the Event Hubs consumer groups shown in the portal. For more information, see the Event Hubs for Apache Kafka FAQ in the Azure documentation.
With fromBeginning: false, the consumer starts at the end of the event hub and only receives new events. Every consumed event arrives on the MQTT topic in the following format, with the event body as a string in the message property:
Verifying the Integration
Install the service and set the parameters with the values from your Azure subscription.
Check that both connections are in the Connected state on the service details page in the Admin UI. If the connection string is wrong, the connections do not reach the connected state.
Publish a test message to
enterprise/hamburg/assembly/line-1/press-01/telemetry, for example with an MQTT client or the Admin UI.Use the Data Explorer to inspect the
/restopic of the telemetry endpoint. On success, the result containserrorCode: 0. If Event Hubs rejects the write, the message contains anerrorproperty instead.Open the telemetry event hub in the Azure portal and check that the event has arrived, for example with the Data Explorer feature of Event Hubs or the incoming messages metric.
Send a test event to the commands event hub, for example with the Data Explorer feature of Event Hubs, and check that it appears on the
enterprise/azure/event-hubs/commandstopic in Connectware.
Service Commissioning File Example
Last updated
Was this helpful?

