Tahu Edge Node / Device
Since Camel 4.8
Only producer is supported
URI format
Tahu Edge Nodes and Devices use the same URI scheme and Tahu Edge Component and Endpoint.
groupId and edgeNodeId are the Sparkplug Group and Edge Node IDs describing the Edge Node.tahu-edge://groupId/edgeNodeId?options
tahu-edge://Basic/EdgeNode?clientId=EdgeClient1&primaryHostId=BasicHostApp&deviceIds=D2,D3,D4
groupId, edgeNodeId, and deviceId are the Sparkplug Group, Edge Node, and Device IDs describing the Device.tahu-edge://groupId/edgeNodeId/deviceId
tahu-edge://Basic/EdgeNode/D2 tahu-edge://Basic/EdgeNode/D3 tahu-edge://Basic/EdgeNode/D4
Configuring Options
Camel components are configured on two separate levels:
-
component level
-
endpoint level
Configuring Component Options
At the component level, you set general and shared configurations that are, then, inherited by the endpoints. It is the highest configuration level.
For example, a component may have security settings, credentials for authentication, urls for network connection and so forth.
Some components only have a few options, and others may have many. Because components typically have pre-configured defaults that are commonly used, then you may often only need to configure a few options on a component; or none at all.
You can configure components using:
-
the Component DSL.
-
in a configuration file (
application.properties,*.yamlfiles, etc). -
directly in the Java code.
Configuring Endpoint Options
You usually spend more time setting up endpoints because they have many options. These options help you customize what you want the endpoint to do. The options are also categorized into whether the endpoint is used as a consumer (from), as a producer (to), or both.
Configuring endpoints is most often done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL and DataFormat DSL as a type safe way of configuring endpoints and data formats in Java.
A good practice when configuring options is to use Property Placeholders.
Property placeholders provide a few benefits:
-
They help prevent using hardcoded urls, port numbers, sensitive information, and other settings.
-
They allow externalizing the configuration from the code.
-
They help the code to become more flexible and reusable.
The following two sections list all the options, firstly for the component followed by the endpoint.
Component Options
The Tahu Edge Node / Device component supports the following options which are listed below.
| Name | Description | Default | Type |
|---|---|---|---|
Whether to fail when an MQTT client ID is longer than 23 characters, the limit of MQTT 3.1.1. A generated client ID is always shorter. | false | boolean | |
Required The MQTT client ID for each server whose definition in the servers option has no client ID. If neither is set, a random client ID that starts with Camel is generated for the server. | String | ||
MQTT connection keep alive timeout, in seconds. | 30 | int | |
The time in milliseconds after a birth or rebirth during which the Edge Node ignores further rebirth requests. Only an Edge Node endpoint of tahu-edge uses it, tahu-host does not. | 5000 | long | |
Required The MQTT servers, as a comma-separated list of definitions with the syntax name:[clientId:](tcp|ssl)://host[:port], for example Mqtt:tcp://localhost:1883. The clientId of a definition replaces the clientId option for that server. A tahu-edge Device endpoint does not use it, as its Edge Node endpoint connects to the servers. | String | ||
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean | |
Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc. | true | boolean | |
The shared configuration of the endpoints. Each endpoint gets a copy of it, which the options of the endpoint then change. | TahuConfiguration | ||
Password for MQTT server authentication. | String | ||
Not supported: Eclipse Tahu creates its MQTT clients without these TLS settings, so the endpoint fails to start when this option is set. An ssl:// server is checked with the default trust store of the JVM, which the javax.net.ssl.* system properties configure. | SSLContextParameters | ||
Not supported: when true and a global SSLContextParameters is configured, the endpoints fail to start, as Eclipse Tahu creates its MQTT clients without these TLS settings. An ssl:// server is checked with the default trust store of the JVM, which the javax.net.ssl.* system properties configure. | false | boolean | |
Username for MQTT server authentication. | String |
Endpoint Options
The Tahu Edge Node / Device endpoint is configured using URI syntax:
tahu-edge:groupId/edgeNode
With the following path and query parameters:
Path Parameters
| Name | Description | Default | Type |
|---|---|---|---|
Required The Sparkplug group ID of the Edge Node. | String | ||
Required The Sparkplug Edge Node ID. With the groupId, it identifies the Edge Node. | String | ||
The Sparkplug device ID of a Device of the Edge Node. With it, the endpoint is a Device endpoint; without it, an Edge Node endpoint. | String |
Query Parameters
| Name | Description | Default | Type |
|---|---|---|---|
Whether to fail when an MQTT client ID is longer than 23 characters, the limit of MQTT 3.1.1. A generated client ID is always shorter. | false | boolean | |
Required The MQTT client ID for each server whose definition in the servers option has no client ID. If neither is set, a random client ID that starts with Camel is generated for the server. | String | ||
MQTT connection keep alive timeout, in seconds. | 30 | int | |
The time in milliseconds after a birth or rebirth during which the Edge Node ignores further rebirth requests. Only an Edge Node endpoint of tahu-edge uses it, tahu-host does not. | 5000 | long | |
Required The MQTT servers, as a comma-separated list of definitions with the syntax name:[clientId:](tcp|ssl)://host[:port], for example Mqtt:tcp://localhost:1883. The clientId of a definition replaces the clientId option for that server. A tahu-edge Device endpoint does not use it, as its Edge Node endpoint connects to the servers. | String | ||
The device IDs of the Devices of the Edge Node, as a comma-separated list. Used by an Edge Node endpoint only. | String | ||
Required The Tahu SparkplugBPayloadMap with every metric of the Edge Node or Device: its name, data type and initial value. The NBIRTH or DBIRTH message has these metrics, and the producer updates their values with each payload it publishes, so a later birth message has the last values. | SparkplugBPayloadMap | ||
The host ID of the primary Host Application of the Edge Node. If set, the Edge Node waits for the STATE message that says this Host Application is online before it publishes its birth messages, and disconnects from a server when it goes offline. Used by an Edge Node endpoint only. | String | ||
The org.eclipse.tahu.message.BdSeqManager that keeps the birth-death sequence number (bdSeq) of the Edge Node from one MQTT session to the next. If not set, a CamelBdSeqManager keeps it in a file below the bdSeqNumPath directory. Used by an Edge Node endpoint only. | org.apache.camel.component.tahu.CamelBdSeqManager | BdSeqManager | |
The directory in which the default bdSeqManager keeps the next birth-death sequence number of the Edge Node, in the file groupId/edgeNode-bdSeqNum below it, named after the IDs of the Edge Node. The process must be able to write to it. Not used when the bdSeqManager option is set. | ${sys:java.io.tmpdir}/CamelTahuTemp | String | |
To use a custom HeaderFilterStrategy to filter headers used as Sparkplug metrics. Default value notice: Defaults to sending all Camel Message headers with name prefixes of CamelTahuMetric., including those with null values. | HeaderFilterStrategy | ||
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean | |
Whether to use metric aliases: Tahu gives each metric a generated alias in the birth messages, and the data messages carry the alias instead of the name. Used by an Edge Node endpoint only. | false | boolean | |
Password for MQTT server authentication. | String | ||
Not supported: Eclipse Tahu creates its MQTT clients without these TLS settings, so the endpoint fails to start when this option is set. An ssl:// server is checked with the default trust store of the JVM, which the javax.net.ssl.* system properties configure. | SSLContextParameters | ||
Username for MQTT server authentication. | String |
Message Headers
The Tahu Edge Node / Device component supports the following message header(s), which is/are listed below:
| Name | Description | Default | Type |
|---|---|---|---|
CamelTahuMessageType (producer) Constant: | The Sparkplug message type. The consumer sets it on the exchange of each message, but not on the exchange of a single metric. The producer sets it to NDATA for an Edge Node and to DDATA for a Device. Enum values:
| String | |
CamelTahuEdgeNodeDescriptor (producer) Constant: | The Edge Node or Device of the message or metric, as groupId/edgeNode or groupId/edgeNode/deviceId. The consumer sets it as a String, and the producer sets the Tahu EdgeNodeDescriptor of the endpoint, a DeviceDescriptor for a Device. | String | |
CamelTahuMessageTimestamp (producer) Constant: | The timestamp of the Sparkplug payload. The consumer sets it in milliseconds since the epoch, and the producer sets the java.util.Date of the payload it publishes. | Long | |
CamelTahuMessageUUID (producer) Constant: | The UUID of the Sparkplug payload. The consumer sets it when the payload has a valid UUID. The producer uses it as the UUID of a payload that it makes from the message, and sets it to the UUID of the payload it publishes, as a String. | UUID | |
CamelTahuMessageSequenceNumber (producer) Constant: | The sequence number of the Sparkplug payload. The consumer sets it when the payload has one, and the producer only when the payload to publish already has one. | Long |
Message Body
The message body at each side of the Tahu Edge Node / Device component: Consumer is the body of the messages the consumer creates, Consumer reply the bodies a consumer that answers its caller can reply with, Producer input the bodies the producer can send or write, and Producer output the body after the producer.
| Side | Body | Description |
|---|---|---|
Producer input |
| A Tahu SparkplugBPayload with the metrics to publish. For any other body the metrics are made from the CamelTahuMetric.<name> headers, and the body, converted to bytes, is the body of the payload (no body gives a payload without body). A body that does not convert to bytes fails. |
Producer output |
|
The bodies are the ones with the default options. A side that is not listed is not known, and tooling does not guess it. The carriers, the sides and the tools that use them are described in Message Body Types.
Usage
Edge Node Endpoint Configuration
Sparkplug Edge Nodes are identified by a unique combination of Group ID and Edge Node ID, the Edge Node Descriptor. These two elements form the path of an Edge Node Endpoint URI. All other Edge Node Endpoint configuration properties use query string variables or are set via Endpoint property setters.
If an Edge Node is tied to a particular Host Application, the primaryHostId query string variable can be set to enable the required Sparkplug behavior.
Metric aliasing is handled automatically by the Eclipse Tahu library and enabled with the useAliases query string variable.
Birth/Death Sequence Numbers
The Sparkplug specification requires careful handling of NBIRTH/NDEATH sequence numbers for Host Applications to correlate Edge Nodes' session behavior with the metrics the Host Application receives.
By default, each Edge Node Endpoint writes a local file to store the next sequence number that Edge Node should use when publishing its NBIRTH message and setting its NDEATH MQTT Will Message when establishing an MQTT Server connection. The local path for this file can be set using the bdSeqNumPath query string variable.
Should another Sparkplug spec-compliant Eclipse Tahu BdSeqManager instance be required, use the bdSeqManager Endpoint property setter method.
Device Endpoint Configuration
Sparkplug Devices are identified by a unique combination of the Edge Node Descriptor to which the Device is connected and the Device’s Device ID. These three elements form the path of a Device Endpoint URI. Since any Sparkplug Device is associated with exactly one Edge Node, an MQTT Server connection and its associated Sparkplug behavior is managed per Edge Node, not per Device. This means all Device Endpoint configuration must be completed prior to starting the Edge Node Producer for a given Device Endpoint.
Device Endpoints inherit all MQTT Server connection information from their associated Edge Node Endpoint. Setting Component- or Endpoint-level configuration values on Device Components or Endpoints is unnecessary and should be avoided.
A Device Producer publishes through the client of its Edge Node Producer and never creates one, so sending to a Device Endpoint while no producer of its Edge Node Endpoint is started fails the exchange with an IllegalStateException.
Edge Node and Device Endpoint Interaction
Sparkplug Edge Nodes are not required to have a Device hierarchy and physical devices may be represented directly as Edge Nodes—this decision is left to Sparkplug application developers.
However if an Edge Node will be reporting Device-level metrics in addition to and Edge Node-level metrics, the Edge Node Endpoint is required to have a deviceIds list configured to publish correct NBIRTH and DBIRTH payloads required by the Sparkplug specification.
Additionally, a Tahu SparkplugBPayloadMap instance is required to be set on each Edge Node and Device Endpoint to populate the NBIRTH/DBIRTH message with the required Sparkplug Metric names and data types. This is accomplished using the metricDataTypePayloadMap Endpoint property setter method.
These requirements allow Sparkplug 3.0.0 compliant behavior.
Message Body
A message body that is a Tahu SparkplugBPayload is published as it is. For any other body the producer makes the payload from the message: each CamelTahuMetric.<name> header is a metric (a header whose value is a Tahu Metric is added as it is), and the body, converted to bytes, is the body of the payload. A text or a byte array body is therefore the body of the published payload, and a message without a body gives a payload without body. A body that does not convert to bytes fails the exchange with an InvalidPayloadException.
Example
The following routes publish a temperature for device D1 of Edge Node EdgeNode in group Basic:
-
The Edge Node endpoint has the MQTT server, the client ID and the device IDs. Its route comes first, so that the Edge Node starts before its device.
-
Both endpoints have the metric definitions of their birth messages, made by a Groovy script.
-
The body is a
SparkplugBPayloadwith the metrics to publish.
- beans:
- name: edgeMetrics
scriptLanguage: groovy
script: |
import org.eclipse.tahu.message.model.*
new SparkplugBPayloadMap.SparkplugBPayloadMapBuilder()
.addMetric(new Metric.MetricBuilder('uptime', MetricDataType.Int64, 0L).createMetric())
.createPayload()
- name: deviceMetrics
scriptLanguage: groovy
script: |
import org.eclipse.tahu.message.model.*
new SparkplugBPayloadMap.SparkplugBPayloadMapBuilder()
.addMetric(new Metric.MetricBuilder('temperature', MetricDataType.Double, 0.0d).createMetric())
.createPayload()
- route:
from:
uri: timer:node
parameters:
delay: -1
repeatCount: 1
steps:
- to:
uri: tahu-edge://Basic/EdgeNode
parameters:
clientId: EdgeClient1
servers: "Mqtt:tcp://localhost:1883"
deviceIds: D1
metricDataTypePayloadMap: "#bean:edgeMetrics"
- route:
from:
uri: timer:report
parameters:
period: 5000
steps:
- setBody:
expression:
groovy:
expression: |
import org.eclipse.tahu.message.model.*
new SparkplugBPayload.SparkplugBPayloadBuilder()
.addMetric(new Metric.MetricBuilder('temperature', MetricDataType.Double, 21.5d).createMetric())
.createPayload()
- to:
uri: tahu-edge://Basic/EdgeNode/D1
parameters:
metricDataTypePayloadMap: "#bean:deviceMetrics" With camel run, add --dep=camel:tahu. The beans are created before the dependencies of the routes are added, and the Groovy scripts need the Tahu classes. |