Tahu Host Application
Since Camel 4.8
Only consumer is supported
URI format
hostId is the Sparkplug Host Application IDtahu-host://hostId?options
tahu-host:BasicHostApp?clientId=HostClient1
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 Host Application 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 | ||
Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | 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 Host Application endpoint is configured using URI syntax:
tahu-host:hostId
With the following path and query parameters:
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 | ||
Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean | |
To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored. | ExceptionHandler | ||
Sets the exchange pattern when the consumer creates an exchange. Enum values:
| ExchangePattern | ||
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 Host Application component supports the following message header(s), which is/are listed below:
| Name | Description | Default | Type |
|---|---|---|---|
CamelTahuMessageType (consumer) 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 (consumer) 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 (consumer) 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 (consumer) 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 (consumer) 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 Host Application 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 |
|---|---|---|
Consumer |
| The body of the Sparkplug payload as a byte array when it has one, else no body, as for most messages and for the exchange of each metric. The metrics are the CamelTahuMetric.<name> headers, each a Tahu Metric. |
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
A Host Application consumer receives the Sparkplug messages of the Edge Nodes and Devices, and gives one exchange for each message, with the CamelTahuMessageType header. Each metric of a message is a header named CamelTahuMetric. followed by the name of the metric, and its value is a Tahu Metric.
In addition, the consumer gives an exchange for each metric: each metric of a birth or data message, and each metric that turns stale when its Edge Node or Device dies. Such an exchange has the CamelTahuEdgeNodeDescriptor header and the header of its metric, but no CamelTahuMessageType header.
The following route logs the temperature of the device in the Tahu Edge example, once for each data message:
- route:
from:
uri: tahu-host:BasicHostApp
parameters:
clientId: HostClient1
servers: "Mqtt:tcp://localhost:1883"
steps:
- filter:
expression:
simple:
expression: "${header.CamelTahuMessageType} == 'DDATA' && ${header[CamelTahuMetric.temperature]} != null"
steps:
- log:
message: "Temperature: ${header[CamelTahuMetric.temperature].value}" One Host Application consumer per JVM
Define only one tahu-host route in a JVM, also across CamelContexts, and including routes that are not started (autoStartup=false): their consumer is created when the route is set up. Eclipse Tahu hands the Sparkplug messages of every Host Application in the JVM to one shared SequenceReorderManager, which gives them to the Host Application created last. With two consumers, all the Sparkplug messages the two receive go to the consumer created last, and the other one gets none of them.
A route that is restarted, reloaded, or removed and added again is fine: its new consumer is the one created last.