This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 7c9afe6373b3 CAMEL-27600: camel-azure-iothub - send over HTTPS,
contentEncoding option, sendTimeout for the twin subscription (#30983)
7c9afe6373b3 is described below
commit 7c9afe6373b35320c0c47b8b0b011352b3cb77d1
Author: allthingssecurity <[email protected]>
AuthorDate: Sat Nov 28 00:25:53 2026 +0530
CAMEL-27600: camel-azure-iothub - send over HTTPS, contentEncoding option,
sendTimeout for the twin subscription (#30983)
1. With protocol=HTTPS no message was ever sent, also with
deliveryMode=TELEMETRY: DeviceClientPool.createClient() always subscribed
to desired properties, which iot-device-client 2.5.1 rejects over HTTPS
with UnsupportedOperationException ("Twin operations are only supported
over MQTT, MQTT_WS, AMQPS, and AMQPS_WS"), so the client creation failed.
The pool now subscribes only when the protocol is not HTTPS, and the
producer fails TWIN and BOTH over HTTPS with an IllegalArgumentException
that names the protocols, before it opens a device client.
2. Telemetry messages always had the content encoding UTF-8, also for a
binary body. The new contentEncoding option (default UTF-8, so nothing
changes by default) sets it, and an empty value sends the message without
a content encoding.
3. sendTimeout did not cover the creation of the device client. The
subscription to desired properties now uses the overload of the SDK with
a timeout, given sendTimeout (DeviceClientPool.acquire/lease and
IoTHubSendOperations take it, the old signatures keep the SDK default).
DeviceClient.open has no timeout in the SDK, so opening the client still
uses the retry policy of the SDK; the sendTimeout description now says
so.
The component is new in 4.24, so no upgrade guide entry. Regenerated
azure-iothub.json (component and catalog copy), the component and endpoint
configurers, the endpoint URI factory, and the component and endpoint DSL.
CAMEL-27600: camel-azure-iothub - review: own pool key for HTTPS clients,
fail start of twin over HTTPS
1. Now that an HTTPS device client can be created, it was pooled under the
same HostName:DeviceId key as the MQTT and AMQPS clients. An MQTT or
AMQPS
endpoint of the same device then reused it, and its TWIN or BOTH send
failed
with the UnsupportedOperationException of the SDK. The pool key of an
HTTPS
client now ends with "|HTTPS". MQTT and AMQPS keep sharing one client, as
IoT Hub allows only one MQTT or AMQP connection per device.
matchesDeviceId strips the suffix before it compares the device id, so
remove(deviceId) also finds an HTTPS client, and remove(deviceId,
connectionString) removes both clients of the device.
2. A producer with deliveryMode TWIN or BOTH and protocol=HTTPS now fails in
doStart with the same message as the per-exchange check, which stays for
the CamelAzureIoTHubDeliveryMode header.
3. The comment of the sendTimeout test describes the behaviour on main.
4. The component page says that twin operations need MQTT, MQTT_WS, AMQPS or
AMQPS_WS, that an HTTPS producer with TWIN or BOTH fails to start, and
that
HTTPS and MQTT/AMQPS endpoints of a device use their own clients.
Tests: IoTHubProducerProtocolOptionsTest sends HTTPS telemetry then a TWIN
update over MQTT for the same device and checks two clients (fails without
the change), checks that TWIN/BOTH over HTTPS fail at start and that the
delivery mode header is still checked per exchange, and that MQTT and AMQPS
share one client. DeviceClientPoolTest removes an HTTPS client by device id.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
.../camel/catalog/components/azure-iothub.json | 32 ++--
.../camel/catalog/docs/azure-iothub-component.adoc | 5 +
.../azure/iothub/IoTHubComponentConfigurer.java | 6 +
.../azure/iothub/IoTHubEndpointConfigurer.java | 6 +
.../azure/iothub/IoTHubEndpointUriFactory.java | 3 +-
.../camel/component/azure/iothub/azure-iothub.json | 32 ++--
.../src/main/docs/azure-iothub-component.adoc | 5 +
.../azure/iothub/IoTHubConfiguration.java | 22 ++-
.../component/azure/iothub/IoTHubProducer.java | 16 +-
.../azure/iothub/client/DeviceClientPool.java | 72 ++++++--
.../iothub/operations/IoTHubSendOperations.java | 13 +-
.../operations/TelemetryDeliveryStrategy.java | 14 +-
.../iothub/IoTHubProducerProtocolOptionsTest.java | 196 +++++++++++++++++++++
.../azure/iothub/client/DeviceClientPoolTest.java | 20 +++
.../dsl/AzureIothubComponentBuilderFactory.java | 35 +++-
.../endpoint/dsl/IoTHubEndpointBuilderFactory.java | 38 +++-
16 files changed, 452 insertions(+), 63 deletions(-)
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/azure-iothub.json
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/azure-iothub.json
index fcd55782b43c..05ddd5d55d7b 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/azure-iothub.json
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/azure-iothub.json
@@ -25,15 +25,16 @@
},
"componentProperties": {
"configuration": { "index": 0, "kind": "property", "displayName":
"Configuration", "group": "producer", "label": "", "required": false, "type":
"object", "javaType":
"org.apache.camel.component.azure.iothub.IoTHubConfiguration", "deprecated":
false, "autowired": false, "secret": false, "description": "The configuration
that each endpoint copies as its defaults, before the endpoint options are
applied." },
- "contentType": { "index": 1, "kind": "property", "displayName": "Content
Type", "group": "producer", "label": "producer", "required": false, "type":
"string", "javaType": "java.lang.String", "deprecated": false, "autowired":
false, "secret": false, "defaultValue": "application\/json",
"configurationClass":
"org.apache.camel.component.azure.iothub.IoTHubConfiguration",
"configurationField": "configuration", "description": "The content type of the
telemetry message, which IoT Hub messa [...]
- "deliveryMode": { "index": 2, "kind": "property", "displayName": "Delivery
Mode", "group": "producer", "label": "producer", "required": false, "type":
"enum", "javaType":
"org.apache.camel.component.azure.iothub.IoTHubDeliveryMode", "enum": [
"TELEMETRY", "TWIN", "BOTH" ], "deprecated": false, "autowired": false,
"secret": false, "defaultValue": "TELEMETRY", "configurationClass":
"org.apache.camel.component.azure.iothub.IoTHubConfiguration",
"configurationField": "configuration", "de [...]
- "lazyStartProducer": { "index": 3, "kind": "property", "displayName":
"Lazy Start Producer", "group": "producer", "label": "producer", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false, "description":
"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 [...]
- "protocol": { "index": 4, "kind": "property", "displayName": "Protocol",
"group": "producer", "label": "producer", "required": false, "type": "enum",
"javaType": "com.microsoft.azure.sdk.iot.device.IotHubClientProtocol", "enum":
[ "HTTPS", "AMQPS", "MQTT", "AMQPS_WS", "MQTT_WS" ], "deprecated": false,
"autowired": false, "secret": false, "defaultValue": "MQTT",
"configurationClass":
"org.apache.camel.component.azure.iothub.IoTHubConfiguration",
"configurationField": "configuration", [...]
- "sendTimeout": { "index": 5, "kind": "property", "displayName": "Send
Timeout", "group": "producer", "label": "producer", "required": false, "type":
"duration", "javaType": "java.time.Duration", "deprecated": false, "autowired":
false, "secret": false, "defaultValue": "10s", "configurationClass":
"org.apache.camel.component.azure.iothub.IoTHubConfiguration",
"configurationField": "configuration", "description": "How long the producer
waits for IoT Hub to acknowledge a telemetry messa [...]
- "autowiredEnabled": { "index": 6, "kind": "property", "displayName":
"Autowired Enabled", "group": "advanced", "label": "advanced", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": true, "description":
"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 t [...]
- "deviceClientEvictionInterval": { "index": 7, "kind": "property",
"displayName": "Device Client Eviction Interval", "group": "advanced", "label":
"advanced", "required": false, "type": "duration", "javaType":
"java.time.Duration", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": "30s", "description": "How often the component checks the pool
for device clients that are unused for longer than deviceClientIdleTimeout, and
closes them. A value of 0 or less uses 3 [...]
- "deviceClientIdleTimeout": { "index": 8, "kind": "property",
"displayName": "Device Client Idle Timeout", "group": "advanced", "label":
"advanced", "required": false, "type": "duration", "javaType":
"java.time.Duration", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": "5m", "description": "How long a pooled device client can be
unused before the component closes it. A client is unused when no producer
sends with it. A value of 0 or less uses 5 minutes." },
- "connectionString": { "index": 9, "kind": "property", "displayName":
"Connection String", "group": "security", "label": "security", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": true, "security": "secret", "configurationClass":
"org.apache.camel.component.azure.iothub.IoTHubConfiguration",
"configurationField": "configuration", "description": "The connection string of
the device, with its HostName, DeviceId and [...]
+ "contentEncoding": { "index": 1, "kind": "property", "displayName":
"Content Encoding", "group": "producer", "label": "producer", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": "UTF-8",
"configurationClass":
"org.apache.camel.component.azure.iothub.IoTHubConfiguration",
"configurationField": "configuration", "description": "Content encoding applied
to telemetry messages. Set it to an empty [...]
+ "contentType": { "index": 2, "kind": "property", "displayName": "Content
Type", "group": "producer", "label": "producer", "required": false, "type":
"string", "javaType": "java.lang.String", "deprecated": false, "autowired":
false, "secret": false, "defaultValue": "application\/json",
"configurationClass":
"org.apache.camel.component.azure.iothub.IoTHubConfiguration",
"configurationField": "configuration", "description": "The content type of the
telemetry message, which IoT Hub messa [...]
+ "deliveryMode": { "index": 3, "kind": "property", "displayName": "Delivery
Mode", "group": "producer", "label": "producer", "required": false, "type":
"enum", "javaType":
"org.apache.camel.component.azure.iothub.IoTHubDeliveryMode", "enum": [
"TELEMETRY", "TWIN", "BOTH" ], "deprecated": false, "autowired": false,
"secret": false, "defaultValue": "TELEMETRY", "configurationClass":
"org.apache.camel.component.azure.iothub.IoTHubConfiguration",
"configurationField": "configuration", "de [...]
+ "lazyStartProducer": { "index": 4, "kind": "property", "displayName":
"Lazy Start Producer", "group": "producer", "label": "producer", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false, "description":
"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 [...]
+ "protocol": { "index": 5, "kind": "property", "displayName": "Protocol",
"group": "producer", "label": "producer", "required": false, "type": "enum",
"javaType": "com.microsoft.azure.sdk.iot.device.IotHubClientProtocol", "enum":
[ "HTTPS", "AMQPS", "MQTT", "AMQPS_WS", "MQTT_WS" ], "deprecated": false,
"autowired": false, "secret": false, "defaultValue": "MQTT",
"configurationClass":
"org.apache.camel.component.azure.iothub.IoTHubConfiguration",
"configurationField": "configuration", [...]
+ "sendTimeout": { "index": 6, "kind": "property", "displayName": "Send
Timeout", "group": "producer", "label": "producer", "required": false, "type":
"duration", "javaType": "java.time.Duration", "deprecated": false, "autowired":
false, "secret": false, "defaultValue": "10s", "configurationClass":
"org.apache.camel.component.azure.iothub.IoTHubConfiguration",
"configurationField": "configuration", "description": "How long the producer
waits for IoT Hub to acknowledge a telemetry messa [...]
+ "autowiredEnabled": { "index": 7, "kind": "property", "displayName":
"Autowired Enabled", "group": "advanced", "label": "advanced", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": true, "description":
"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 t [...]
+ "deviceClientEvictionInterval": { "index": 8, "kind": "property",
"displayName": "Device Client Eviction Interval", "group": "advanced", "label":
"advanced", "required": false, "type": "duration", "javaType":
"java.time.Duration", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": "30s", "description": "How often the component checks the pool
for device clients that are unused for longer than deviceClientIdleTimeout, and
closes them. A value of 0 or less uses 3 [...]
+ "deviceClientIdleTimeout": { "index": 9, "kind": "property",
"displayName": "Device Client Idle Timeout", "group": "advanced", "label":
"advanced", "required": false, "type": "duration", "javaType":
"java.time.Duration", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": "5m", "description": "How long a pooled device client can be
unused before the component closes it. A client is unused when no producer
sends with it. A value of 0 or less uses 5 minutes." },
+ "connectionString": { "index": 10, "kind": "property", "displayName":
"Connection String", "group": "security", "label": "security", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": true, "security": "secret", "configurationClass":
"org.apache.camel.component.azure.iothub.IoTHubConfiguration",
"configurationField": "configuration", "description": "The connection string of
the device, with its HostName, DeviceId an [...]
},
"headers": {
"CamelAzureIoTHubDeviceId": { "index": 0, "kind": "header", "displayName":
"", "group": "producer", "label": "producer", "required": false, "javaType":
"String", "deprecated": false, "autowired": false, "secret": false,
"description": "The ID of the device that sends the message. It replaces the
deviceId of the endpoint, unless it is empty.", "constantName":
"org.apache.camel.component.azure.iothub.IoTHubConstants#DEVICE_ID" },
@@ -43,11 +44,12 @@
},
"properties": {
"deviceId": { "index": 0, "kind": "path", "displayName": "Device Id",
"group": "producer", "label": "producer", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "autowired": false,
"secret": false, "configurationClass":
"org.apache.camel.component.azure.iothub.IoTHubConfiguration",
"configurationField": "configuration", "description": "The ID of the device
that sends the message. It must match the DeviceId of the connection string.
The CamelAz [...]
- "contentType": { "index": 1, "kind": "parameter", "displayName": "Content
Type", "group": "producer", "label": "producer", "required": false, "type":
"string", "javaType": "java.lang.String", "deprecated": false, "autowired":
false, "secret": false, "defaultValue": "application\/json",
"configurationClass":
"org.apache.camel.component.azure.iothub.IoTHubConfiguration",
"configurationField": "configuration", "description": "The content type of the
telemetry message, which IoT Hub mess [...]
- "deliveryMode": { "index": 2, "kind": "parameter", "displayName":
"Delivery Mode", "group": "producer", "label": "producer", "required": false,
"type": "enum", "javaType":
"org.apache.camel.component.azure.iothub.IoTHubDeliveryMode", "enum": [
"TELEMETRY", "TWIN", "BOTH" ], "deprecated": false, "autowired": false,
"secret": false, "defaultValue": "TELEMETRY", "configurationClass":
"org.apache.camel.component.azure.iothub.IoTHubConfiguration",
"configurationField": "configuration", "d [...]
- "protocol": { "index": 3, "kind": "parameter", "displayName": "Protocol",
"group": "producer", "label": "producer", "required": false, "type": "enum",
"javaType": "com.microsoft.azure.sdk.iot.device.IotHubClientProtocol", "enum":
[ "HTTPS", "AMQPS", "MQTT", "AMQPS_WS", "MQTT_WS" ], "deprecated": false,
"autowired": false, "secret": false, "defaultValue": "MQTT",
"configurationClass":
"org.apache.camel.component.azure.iothub.IoTHubConfiguration",
"configurationField": "configuration", [...]
- "sendTimeout": { "index": 4, "kind": "parameter", "displayName": "Send
Timeout", "group": "producer", "label": "producer", "required": false, "type":
"duration", "javaType": "java.time.Duration", "deprecated": false, "autowired":
false, "secret": false, "defaultValue": "10s", "configurationClass":
"org.apache.camel.component.azure.iothub.IoTHubConfiguration",
"configurationField": "configuration", "description": "How long the producer
waits for IoT Hub to acknowledge a telemetry mess [...]
- "lazyStartProducer": { "index": 5, "kind": "parameter", "displayName":
"Lazy Start Producer", "group": "producer (advanced)", "label":
"producer,advanced", "required": false, "type": "boolean", "javaType":
"boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "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 produc [...]
- "connectionString": { "index": 6, "kind": "parameter", "displayName":
"Connection String", "group": "security", "label": "security", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": true, "security": "secret", "configurationClass":
"org.apache.camel.component.azure.iothub.IoTHubConfiguration",
"configurationField": "configuration", "description": "The connection string of
the device, with its HostName, DeviceId an [...]
+ "contentEncoding": { "index": 1, "kind": "parameter", "displayName":
"Content Encoding", "group": "producer", "label": "producer", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": "UTF-8",
"configurationClass":
"org.apache.camel.component.azure.iothub.IoTHubConfiguration",
"configurationField": "configuration", "description": "Content encoding applied
to telemetry messages. Set it to an empt [...]
+ "contentType": { "index": 2, "kind": "parameter", "displayName": "Content
Type", "group": "producer", "label": "producer", "required": false, "type":
"string", "javaType": "java.lang.String", "deprecated": false, "autowired":
false, "secret": false, "defaultValue": "application\/json",
"configurationClass":
"org.apache.camel.component.azure.iothub.IoTHubConfiguration",
"configurationField": "configuration", "description": "The content type of the
telemetry message, which IoT Hub mess [...]
+ "deliveryMode": { "index": 3, "kind": "parameter", "displayName":
"Delivery Mode", "group": "producer", "label": "producer", "required": false,
"type": "enum", "javaType":
"org.apache.camel.component.azure.iothub.IoTHubDeliveryMode", "enum": [
"TELEMETRY", "TWIN", "BOTH" ], "deprecated": false, "autowired": false,
"secret": false, "defaultValue": "TELEMETRY", "configurationClass":
"org.apache.camel.component.azure.iothub.IoTHubConfiguration",
"configurationField": "configuration", "d [...]
+ "protocol": { "index": 4, "kind": "parameter", "displayName": "Protocol",
"group": "producer", "label": "producer", "required": false, "type": "enum",
"javaType": "com.microsoft.azure.sdk.iot.device.IotHubClientProtocol", "enum":
[ "HTTPS", "AMQPS", "MQTT", "AMQPS_WS", "MQTT_WS" ], "deprecated": false,
"autowired": false, "secret": false, "defaultValue": "MQTT",
"configurationClass":
"org.apache.camel.component.azure.iothub.IoTHubConfiguration",
"configurationField": "configuration", [...]
+ "sendTimeout": { "index": 5, "kind": "parameter", "displayName": "Send
Timeout", "group": "producer", "label": "producer", "required": false, "type":
"duration", "javaType": "java.time.Duration", "deprecated": false, "autowired":
false, "secret": false, "defaultValue": "10s", "configurationClass":
"org.apache.camel.component.azure.iothub.IoTHubConfiguration",
"configurationField": "configuration", "description": "How long the producer
waits for IoT Hub to acknowledge a telemetry mess [...]
+ "lazyStartProducer": { "index": 6, "kind": "parameter", "displayName":
"Lazy Start Producer", "group": "producer (advanced)", "label":
"producer,advanced", "required": false, "type": "boolean", "javaType":
"boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "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 produc [...]
+ "connectionString": { "index": 7, "kind": "parameter", "displayName":
"Connection String", "group": "security", "label": "security", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": true, "security": "secret", "configurationClass":
"org.apache.camel.component.azure.iothub.IoTHubConfiguration",
"configurationField": "configuration", "description": "The connection string of
the device, with its HostName, DeviceId an [...]
}
}
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/azure-iothub-component.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/azure-iothub-component.adoc
index bad5bb952cf0..b86eaa00e74f 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/azure-iothub-component.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/azure-iothub-component.adoc
@@ -63,6 +63,11 @@ how the body is interpreted:
* `BOTH` - sends the message body as telemetry and applies twin reported
properties from the
`CamelAzureIoTHubTwinProperties` header.
+`TWIN` and `BOTH` update the device twin, which the Azure IoT SDK supports
only over `MQTT`, `MQTT_WS`, `AMQPS` and
+`AMQPS_WS`. With `protocol=HTTPS` only `TELEMETRY` works: a producer with
`deliveryMode` `TWIN` or `BOTH` fails to
+start, and a message whose `CamelAzureIoTHubDeliveryMode` header asks for a
twin update fails. An HTTPS endpoint and an
+MQTT or AMQPS endpoint of the same device each open their own device client.
+
Any payload decoding (for example Protobuf or CloudEvent to `Map`) must be
done by a
preceding processor in the route; this component is payload-agnostic.
diff --git
a/components/camel-azure/camel-azure-iothub/src/generated/java/org/apache/camel/component/azure/iothub/IoTHubComponentConfigurer.java
b/components/camel-azure/camel-azure-iothub/src/generated/java/org/apache/camel/component/azure/iothub/IoTHubComponentConfigurer.java
index d6f11900a2dd..620e09072fa9 100644
---
a/components/camel-azure/camel-azure-iothub/src/generated/java/org/apache/camel/component/azure/iothub/IoTHubComponentConfigurer.java
+++
b/components/camel-azure/camel-azure-iothub/src/generated/java/org/apache/camel/component/azure/iothub/IoTHubComponentConfigurer.java
@@ -36,6 +36,8 @@ public class IoTHubComponentConfigurer extends
PropertyConfigurerSupport impleme
case "configuration": target.setConfiguration(property(camelContext,
org.apache.camel.component.azure.iothub.IoTHubConfiguration.class, value));
return true;
case "connectionstring":
case "connectionString":
getOrCreateConfiguration(target).setConnectionString(property(camelContext,
java.lang.String.class, value)); return true;
+ case "contentencoding":
+ case "contentEncoding":
getOrCreateConfiguration(target).setContentEncoding(property(camelContext,
java.lang.String.class, value)); return true;
case "contenttype":
case "contentType":
getOrCreateConfiguration(target).setContentType(property(camelContext,
java.lang.String.class, value)); return true;
case "deliverymode":
@@ -61,6 +63,8 @@ public class IoTHubComponentConfigurer extends
PropertyConfigurerSupport impleme
case "configuration": return
org.apache.camel.component.azure.iothub.IoTHubConfiguration.class;
case "connectionstring":
case "connectionString": return java.lang.String.class;
+ case "contentencoding":
+ case "contentEncoding": return java.lang.String.class;
case "contenttype":
case "contentType": return java.lang.String.class;
case "deliverymode":
@@ -87,6 +91,8 @@ public class IoTHubComponentConfigurer extends
PropertyConfigurerSupport impleme
case "configuration": return target.getConfiguration();
case "connectionstring":
case "connectionString": return
getOrCreateConfiguration(target).getConnectionString();
+ case "contentencoding":
+ case "contentEncoding": return
getOrCreateConfiguration(target).getContentEncoding();
case "contenttype":
case "contentType": return
getOrCreateConfiguration(target).getContentType();
case "deliverymode":
diff --git
a/components/camel-azure/camel-azure-iothub/src/generated/java/org/apache/camel/component/azure/iothub/IoTHubEndpointConfigurer.java
b/components/camel-azure/camel-azure-iothub/src/generated/java/org/apache/camel/component/azure/iothub/IoTHubEndpointConfigurer.java
index 1c63134ae5e8..e13a8e9fc87f 100644
---
a/components/camel-azure/camel-azure-iothub/src/generated/java/org/apache/camel/component/azure/iothub/IoTHubEndpointConfigurer.java
+++
b/components/camel-azure/camel-azure-iothub/src/generated/java/org/apache/camel/component/azure/iothub/IoTHubEndpointConfigurer.java
@@ -26,6 +26,8 @@ public class IoTHubEndpointConfigurer extends
PropertyConfigurerSupport implemen
switch (ignoreCase ? name.toLowerCase(Locale.ROOT) : name) {
case "connectionstring":
case "connectionString":
target.getConfiguration().setConnectionString(property(camelContext,
java.lang.String.class, value)); return true;
+ case "contentencoding":
+ case "contentEncoding":
target.getConfiguration().setContentEncoding(property(camelContext,
java.lang.String.class, value)); return true;
case "contenttype":
case "contentType":
target.getConfiguration().setContentType(property(camelContext,
java.lang.String.class, value)); return true;
case "deliverymode":
@@ -44,6 +46,8 @@ public class IoTHubEndpointConfigurer extends
PropertyConfigurerSupport implemen
switch (ignoreCase ? name.toLowerCase(Locale.ROOT) : name) {
case "connectionstring":
case "connectionString": return java.lang.String.class;
+ case "contentencoding":
+ case "contentEncoding": return java.lang.String.class;
case "contenttype":
case "contentType": return java.lang.String.class;
case "deliverymode":
@@ -63,6 +67,8 @@ public class IoTHubEndpointConfigurer extends
PropertyConfigurerSupport implemen
switch (ignoreCase ? name.toLowerCase(Locale.ROOT) : name) {
case "connectionstring":
case "connectionString": return
target.getConfiguration().getConnectionString();
+ case "contentencoding":
+ case "contentEncoding": return
target.getConfiguration().getContentEncoding();
case "contenttype":
case "contentType": return target.getConfiguration().getContentType();
case "deliverymode":
diff --git
a/components/camel-azure/camel-azure-iothub/src/generated/java/org/apache/camel/component/azure/iothub/IoTHubEndpointUriFactory.java
b/components/camel-azure/camel-azure-iothub/src/generated/java/org/apache/camel/component/azure/iothub/IoTHubEndpointUriFactory.java
index 38200f96c3b7..ffc907685a09 100644
---
a/components/camel-azure/camel-azure-iothub/src/generated/java/org/apache/camel/component/azure/iothub/IoTHubEndpointUriFactory.java
+++
b/components/camel-azure/camel-azure-iothub/src/generated/java/org/apache/camel/component/azure/iothub/IoTHubEndpointUriFactory.java
@@ -24,8 +24,9 @@ public class IoTHubEndpointUriFactory extends
org.apache.camel.support.component
private static final Set<String> ENDPOINT_IDENTITY_PROPERTY_NAMES;
private static final Map<String, String> MULTI_VALUE_PREFIXES;
static {
- Set<String> props = new HashSet<>(7);
+ Set<String> props = new HashSet<>(8);
props.add("connectionString");
+ props.add("contentEncoding");
props.add("contentType");
props.add("deliveryMode");
props.add("deviceId");
diff --git
a/components/camel-azure/camel-azure-iothub/src/generated/resources/META-INF/org/apache/camel/component/azure/iothub/azure-iothub.json
b/components/camel-azure/camel-azure-iothub/src/generated/resources/META-INF/org/apache/camel/component/azure/iothub/azure-iothub.json
index fcd55782b43c..05ddd5d55d7b 100644
---
a/components/camel-azure/camel-azure-iothub/src/generated/resources/META-INF/org/apache/camel/component/azure/iothub/azure-iothub.json
+++
b/components/camel-azure/camel-azure-iothub/src/generated/resources/META-INF/org/apache/camel/component/azure/iothub/azure-iothub.json
@@ -25,15 +25,16 @@
},
"componentProperties": {
"configuration": { "index": 0, "kind": "property", "displayName":
"Configuration", "group": "producer", "label": "", "required": false, "type":
"object", "javaType":
"org.apache.camel.component.azure.iothub.IoTHubConfiguration", "deprecated":
false, "autowired": false, "secret": false, "description": "The configuration
that each endpoint copies as its defaults, before the endpoint options are
applied." },
- "contentType": { "index": 1, "kind": "property", "displayName": "Content
Type", "group": "producer", "label": "producer", "required": false, "type":
"string", "javaType": "java.lang.String", "deprecated": false, "autowired":
false, "secret": false, "defaultValue": "application\/json",
"configurationClass":
"org.apache.camel.component.azure.iothub.IoTHubConfiguration",
"configurationField": "configuration", "description": "The content type of the
telemetry message, which IoT Hub messa [...]
- "deliveryMode": { "index": 2, "kind": "property", "displayName": "Delivery
Mode", "group": "producer", "label": "producer", "required": false, "type":
"enum", "javaType":
"org.apache.camel.component.azure.iothub.IoTHubDeliveryMode", "enum": [
"TELEMETRY", "TWIN", "BOTH" ], "deprecated": false, "autowired": false,
"secret": false, "defaultValue": "TELEMETRY", "configurationClass":
"org.apache.camel.component.azure.iothub.IoTHubConfiguration",
"configurationField": "configuration", "de [...]
- "lazyStartProducer": { "index": 3, "kind": "property", "displayName":
"Lazy Start Producer", "group": "producer", "label": "producer", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false, "description":
"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 [...]
- "protocol": { "index": 4, "kind": "property", "displayName": "Protocol",
"group": "producer", "label": "producer", "required": false, "type": "enum",
"javaType": "com.microsoft.azure.sdk.iot.device.IotHubClientProtocol", "enum":
[ "HTTPS", "AMQPS", "MQTT", "AMQPS_WS", "MQTT_WS" ], "deprecated": false,
"autowired": false, "secret": false, "defaultValue": "MQTT",
"configurationClass":
"org.apache.camel.component.azure.iothub.IoTHubConfiguration",
"configurationField": "configuration", [...]
- "sendTimeout": { "index": 5, "kind": "property", "displayName": "Send
Timeout", "group": "producer", "label": "producer", "required": false, "type":
"duration", "javaType": "java.time.Duration", "deprecated": false, "autowired":
false, "secret": false, "defaultValue": "10s", "configurationClass":
"org.apache.camel.component.azure.iothub.IoTHubConfiguration",
"configurationField": "configuration", "description": "How long the producer
waits for IoT Hub to acknowledge a telemetry messa [...]
- "autowiredEnabled": { "index": 6, "kind": "property", "displayName":
"Autowired Enabled", "group": "advanced", "label": "advanced", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": true, "description":
"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 t [...]
- "deviceClientEvictionInterval": { "index": 7, "kind": "property",
"displayName": "Device Client Eviction Interval", "group": "advanced", "label":
"advanced", "required": false, "type": "duration", "javaType":
"java.time.Duration", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": "30s", "description": "How often the component checks the pool
for device clients that are unused for longer than deviceClientIdleTimeout, and
closes them. A value of 0 or less uses 3 [...]
- "deviceClientIdleTimeout": { "index": 8, "kind": "property",
"displayName": "Device Client Idle Timeout", "group": "advanced", "label":
"advanced", "required": false, "type": "duration", "javaType":
"java.time.Duration", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": "5m", "description": "How long a pooled device client can be
unused before the component closes it. A client is unused when no producer
sends with it. A value of 0 or less uses 5 minutes." },
- "connectionString": { "index": 9, "kind": "property", "displayName":
"Connection String", "group": "security", "label": "security", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": true, "security": "secret", "configurationClass":
"org.apache.camel.component.azure.iothub.IoTHubConfiguration",
"configurationField": "configuration", "description": "The connection string of
the device, with its HostName, DeviceId and [...]
+ "contentEncoding": { "index": 1, "kind": "property", "displayName":
"Content Encoding", "group": "producer", "label": "producer", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": "UTF-8",
"configurationClass":
"org.apache.camel.component.azure.iothub.IoTHubConfiguration",
"configurationField": "configuration", "description": "Content encoding applied
to telemetry messages. Set it to an empty [...]
+ "contentType": { "index": 2, "kind": "property", "displayName": "Content
Type", "group": "producer", "label": "producer", "required": false, "type":
"string", "javaType": "java.lang.String", "deprecated": false, "autowired":
false, "secret": false, "defaultValue": "application\/json",
"configurationClass":
"org.apache.camel.component.azure.iothub.IoTHubConfiguration",
"configurationField": "configuration", "description": "The content type of the
telemetry message, which IoT Hub messa [...]
+ "deliveryMode": { "index": 3, "kind": "property", "displayName": "Delivery
Mode", "group": "producer", "label": "producer", "required": false, "type":
"enum", "javaType":
"org.apache.camel.component.azure.iothub.IoTHubDeliveryMode", "enum": [
"TELEMETRY", "TWIN", "BOTH" ], "deprecated": false, "autowired": false,
"secret": false, "defaultValue": "TELEMETRY", "configurationClass":
"org.apache.camel.component.azure.iothub.IoTHubConfiguration",
"configurationField": "configuration", "de [...]
+ "lazyStartProducer": { "index": 4, "kind": "property", "displayName":
"Lazy Start Producer", "group": "producer", "label": "producer", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false, "description":
"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 [...]
+ "protocol": { "index": 5, "kind": "property", "displayName": "Protocol",
"group": "producer", "label": "producer", "required": false, "type": "enum",
"javaType": "com.microsoft.azure.sdk.iot.device.IotHubClientProtocol", "enum":
[ "HTTPS", "AMQPS", "MQTT", "AMQPS_WS", "MQTT_WS" ], "deprecated": false,
"autowired": false, "secret": false, "defaultValue": "MQTT",
"configurationClass":
"org.apache.camel.component.azure.iothub.IoTHubConfiguration",
"configurationField": "configuration", [...]
+ "sendTimeout": { "index": 6, "kind": "property", "displayName": "Send
Timeout", "group": "producer", "label": "producer", "required": false, "type":
"duration", "javaType": "java.time.Duration", "deprecated": false, "autowired":
false, "secret": false, "defaultValue": "10s", "configurationClass":
"org.apache.camel.component.azure.iothub.IoTHubConfiguration",
"configurationField": "configuration", "description": "How long the producer
waits for IoT Hub to acknowledge a telemetry messa [...]
+ "autowiredEnabled": { "index": 7, "kind": "property", "displayName":
"Autowired Enabled", "group": "advanced", "label": "advanced", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": true, "description":
"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 t [...]
+ "deviceClientEvictionInterval": { "index": 8, "kind": "property",
"displayName": "Device Client Eviction Interval", "group": "advanced", "label":
"advanced", "required": false, "type": "duration", "javaType":
"java.time.Duration", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": "30s", "description": "How often the component checks the pool
for device clients that are unused for longer than deviceClientIdleTimeout, and
closes them. A value of 0 or less uses 3 [...]
+ "deviceClientIdleTimeout": { "index": 9, "kind": "property",
"displayName": "Device Client Idle Timeout", "group": "advanced", "label":
"advanced", "required": false, "type": "duration", "javaType":
"java.time.Duration", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": "5m", "description": "How long a pooled device client can be
unused before the component closes it. A client is unused when no producer
sends with it. A value of 0 or less uses 5 minutes." },
+ "connectionString": { "index": 10, "kind": "property", "displayName":
"Connection String", "group": "security", "label": "security", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": true, "security": "secret", "configurationClass":
"org.apache.camel.component.azure.iothub.IoTHubConfiguration",
"configurationField": "configuration", "description": "The connection string of
the device, with its HostName, DeviceId an [...]
},
"headers": {
"CamelAzureIoTHubDeviceId": { "index": 0, "kind": "header", "displayName":
"", "group": "producer", "label": "producer", "required": false, "javaType":
"String", "deprecated": false, "autowired": false, "secret": false,
"description": "The ID of the device that sends the message. It replaces the
deviceId of the endpoint, unless it is empty.", "constantName":
"org.apache.camel.component.azure.iothub.IoTHubConstants#DEVICE_ID" },
@@ -43,11 +44,12 @@
},
"properties": {
"deviceId": { "index": 0, "kind": "path", "displayName": "Device Id",
"group": "producer", "label": "producer", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "autowired": false,
"secret": false, "configurationClass":
"org.apache.camel.component.azure.iothub.IoTHubConfiguration",
"configurationField": "configuration", "description": "The ID of the device
that sends the message. It must match the DeviceId of the connection string.
The CamelAz [...]
- "contentType": { "index": 1, "kind": "parameter", "displayName": "Content
Type", "group": "producer", "label": "producer", "required": false, "type":
"string", "javaType": "java.lang.String", "deprecated": false, "autowired":
false, "secret": false, "defaultValue": "application\/json",
"configurationClass":
"org.apache.camel.component.azure.iothub.IoTHubConfiguration",
"configurationField": "configuration", "description": "The content type of the
telemetry message, which IoT Hub mess [...]
- "deliveryMode": { "index": 2, "kind": "parameter", "displayName":
"Delivery Mode", "group": "producer", "label": "producer", "required": false,
"type": "enum", "javaType":
"org.apache.camel.component.azure.iothub.IoTHubDeliveryMode", "enum": [
"TELEMETRY", "TWIN", "BOTH" ], "deprecated": false, "autowired": false,
"secret": false, "defaultValue": "TELEMETRY", "configurationClass":
"org.apache.camel.component.azure.iothub.IoTHubConfiguration",
"configurationField": "configuration", "d [...]
- "protocol": { "index": 3, "kind": "parameter", "displayName": "Protocol",
"group": "producer", "label": "producer", "required": false, "type": "enum",
"javaType": "com.microsoft.azure.sdk.iot.device.IotHubClientProtocol", "enum":
[ "HTTPS", "AMQPS", "MQTT", "AMQPS_WS", "MQTT_WS" ], "deprecated": false,
"autowired": false, "secret": false, "defaultValue": "MQTT",
"configurationClass":
"org.apache.camel.component.azure.iothub.IoTHubConfiguration",
"configurationField": "configuration", [...]
- "sendTimeout": { "index": 4, "kind": "parameter", "displayName": "Send
Timeout", "group": "producer", "label": "producer", "required": false, "type":
"duration", "javaType": "java.time.Duration", "deprecated": false, "autowired":
false, "secret": false, "defaultValue": "10s", "configurationClass":
"org.apache.camel.component.azure.iothub.IoTHubConfiguration",
"configurationField": "configuration", "description": "How long the producer
waits for IoT Hub to acknowledge a telemetry mess [...]
- "lazyStartProducer": { "index": 5, "kind": "parameter", "displayName":
"Lazy Start Producer", "group": "producer (advanced)", "label":
"producer,advanced", "required": false, "type": "boolean", "javaType":
"boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "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 produc [...]
- "connectionString": { "index": 6, "kind": "parameter", "displayName":
"Connection String", "group": "security", "label": "security", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": true, "security": "secret", "configurationClass":
"org.apache.camel.component.azure.iothub.IoTHubConfiguration",
"configurationField": "configuration", "description": "The connection string of
the device, with its HostName, DeviceId an [...]
+ "contentEncoding": { "index": 1, "kind": "parameter", "displayName":
"Content Encoding", "group": "producer", "label": "producer", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": "UTF-8",
"configurationClass":
"org.apache.camel.component.azure.iothub.IoTHubConfiguration",
"configurationField": "configuration", "description": "Content encoding applied
to telemetry messages. Set it to an empt [...]
+ "contentType": { "index": 2, "kind": "parameter", "displayName": "Content
Type", "group": "producer", "label": "producer", "required": false, "type":
"string", "javaType": "java.lang.String", "deprecated": false, "autowired":
false, "secret": false, "defaultValue": "application\/json",
"configurationClass":
"org.apache.camel.component.azure.iothub.IoTHubConfiguration",
"configurationField": "configuration", "description": "The content type of the
telemetry message, which IoT Hub mess [...]
+ "deliveryMode": { "index": 3, "kind": "parameter", "displayName":
"Delivery Mode", "group": "producer", "label": "producer", "required": false,
"type": "enum", "javaType":
"org.apache.camel.component.azure.iothub.IoTHubDeliveryMode", "enum": [
"TELEMETRY", "TWIN", "BOTH" ], "deprecated": false, "autowired": false,
"secret": false, "defaultValue": "TELEMETRY", "configurationClass":
"org.apache.camel.component.azure.iothub.IoTHubConfiguration",
"configurationField": "configuration", "d [...]
+ "protocol": { "index": 4, "kind": "parameter", "displayName": "Protocol",
"group": "producer", "label": "producer", "required": false, "type": "enum",
"javaType": "com.microsoft.azure.sdk.iot.device.IotHubClientProtocol", "enum":
[ "HTTPS", "AMQPS", "MQTT", "AMQPS_WS", "MQTT_WS" ], "deprecated": false,
"autowired": false, "secret": false, "defaultValue": "MQTT",
"configurationClass":
"org.apache.camel.component.azure.iothub.IoTHubConfiguration",
"configurationField": "configuration", [...]
+ "sendTimeout": { "index": 5, "kind": "parameter", "displayName": "Send
Timeout", "group": "producer", "label": "producer", "required": false, "type":
"duration", "javaType": "java.time.Duration", "deprecated": false, "autowired":
false, "secret": false, "defaultValue": "10s", "configurationClass":
"org.apache.camel.component.azure.iothub.IoTHubConfiguration",
"configurationField": "configuration", "description": "How long the producer
waits for IoT Hub to acknowledge a telemetry mess [...]
+ "lazyStartProducer": { "index": 6, "kind": "parameter", "displayName":
"Lazy Start Producer", "group": "producer (advanced)", "label":
"producer,advanced", "required": false, "type": "boolean", "javaType":
"boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "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 produc [...]
+ "connectionString": { "index": 7, "kind": "parameter", "displayName":
"Connection String", "group": "security", "label": "security", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": true, "security": "secret", "configurationClass":
"org.apache.camel.component.azure.iothub.IoTHubConfiguration",
"configurationField": "configuration", "description": "The connection string of
the device, with its HostName, DeviceId an [...]
}
}
diff --git
a/components/camel-azure/camel-azure-iothub/src/main/docs/azure-iothub-component.adoc
b/components/camel-azure/camel-azure-iothub/src/main/docs/azure-iothub-component.adoc
index bad5bb952cf0..b86eaa00e74f 100644
---
a/components/camel-azure/camel-azure-iothub/src/main/docs/azure-iothub-component.adoc
+++
b/components/camel-azure/camel-azure-iothub/src/main/docs/azure-iothub-component.adoc
@@ -63,6 +63,11 @@ how the body is interpreted:
* `BOTH` - sends the message body as telemetry and applies twin reported
properties from the
`CamelAzureIoTHubTwinProperties` header.
+`TWIN` and `BOTH` update the device twin, which the Azure IoT SDK supports
only over `MQTT`, `MQTT_WS`, `AMQPS` and
+`AMQPS_WS`. With `protocol=HTTPS` only `TELEMETRY` works: a producer with
`deliveryMode` `TWIN` or `BOTH` fails to
+start, and a message whose `CamelAzureIoTHubDeliveryMode` header asks for a
twin update fails. An HTTPS endpoint and an
+MQTT or AMQPS endpoint of the same device each open their own device client.
+
Any payload decoding (for example Protobuf or CloudEvent to `Map`) must be
done by a
preceding processor in the route; this component is payload-agnostic.
diff --git
a/components/camel-azure/camel-azure-iothub/src/main/java/org/apache/camel/component/azure/iothub/IoTHubConfiguration.java
b/components/camel-azure/camel-azure-iothub/src/main/java/org/apache/camel/component/azure/iothub/IoTHubConfiguration.java
index 405b66903224..d77293c44486 100644
---
a/components/camel-azure/camel-azure-iothub/src/main/java/org/apache/camel/component/azure/iothub/IoTHubConfiguration.java
+++
b/components/camel-azure/camel-azure-iothub/src/main/java/org/apache/camel/component/azure/iothub/IoTHubConfiguration.java
@@ -35,7 +35,8 @@ public class IoTHubConfiguration implements Cloneable {
@UriParam(label = "security", secret = true,
description = "The connection string of the device, with its
HostName, DeviceId and SharedAccessKey. The"
+ " producer opens one device client per hub,
device and module of the connection string, and"
- + " reuses it. The
CamelAzureIoTHubConnectionString header replaces this option.")
+ + " reuses it; an HTTPS endpoint uses a client of
its own. The CamelAzureIoTHubConnectionString"
+ + " header replaces this option.")
private String connectionString;
@UriParam(label = "producer", defaultValue = "MQTT",
@@ -52,12 +53,19 @@ public class IoTHubConfiguration implements Cloneable {
@UriParam(label = "producer", defaultValue = "application/json",
description = "The content type of the telemetry message, which
IoT Hub message routing needs to query the"
- + " body. The producer always sets the content
encoding to UTF-8.")
+ + " body. The contentEncoding option sets the
content encoding.")
private String contentType = "application/json";
+ @UriParam(label = "producer", defaultValue = "UTF-8",
+ description = "Content encoding applied to telemetry messages.
Set it to an empty value to send telemetry"
+ + " without a content encoding, for example for a
binary body such as Avro or Protobuf.")
+ private String contentEncoding = "UTF-8";
+
@UriParam(label = "producer", defaultValue = "10s",
description = "How long the producer waits for IoT Hub to
acknowledge a telemetry message, and for each device"
- + " twin request: getting the twin and updating
its reported properties.")
+ + " twin request: getting the twin, updating its
reported properties, and the subscription to"
+ + " desired properties when a device client is
created. Opening the device client uses the retry"
+ + " policy of the Azure IoT SDK and is not limited
by this timeout.")
private Duration sendTimeout = Duration.ofSeconds(10);
public String getDeviceId() {
@@ -100,6 +108,14 @@ public class IoTHubConfiguration implements Cloneable {
this.contentType = contentType;
}
+ public String getContentEncoding() {
+ return contentEncoding;
+ }
+
+ public void setContentEncoding(String contentEncoding) {
+ this.contentEncoding = contentEncoding;
+ }
+
public Duration getSendTimeout() {
return sendTimeout;
}
diff --git
a/components/camel-azure/camel-azure-iothub/src/main/java/org/apache/camel/component/azure/iothub/IoTHubProducer.java
b/components/camel-azure/camel-azure-iothub/src/main/java/org/apache/camel/component/azure/iothub/IoTHubProducer.java
index 63321be86973..ef5bdbc72fab 100644
---
a/components/camel-azure/camel-azure-iothub/src/main/java/org/apache/camel/component/azure/iothub/IoTHubProducer.java
+++
b/components/camel-azure/camel-azure-iothub/src/main/java/org/apache/camel/component/azure/iothub/IoTHubProducer.java
@@ -43,15 +43,17 @@ public class IoTHubProducer extends DefaultProducer {
protected void doStart() throws Exception {
super.doStart();
final IoTHubConfiguration config = getConfiguration();
+ // a route that can never send: fail at startup, the
CamelAzureIoTHubDeliveryMode header is checked per exchange
+ checkProtocolSupportsDeliveryMode(config.getProtocol(),
config.getDeliveryMode());
IoTHubComponent component = (IoTHubComponent)
getEndpoint().getComponent();
pool = component.getOrCreateClientPool();
List<DeliveryStrategy> strategies = List.of(
- new TelemetryDeliveryStrategy(config.getContentType(),
config.getSendTimeout()),
+ new TelemetryDeliveryStrategy(config.getContentType(),
config.getContentEncoding(), config.getSendTimeout()),
new TwinDeliveryStrategy(config.getSendTimeout()));
- operations = new IoTHubSendOperations(pool, strategies);
+ operations = new IoTHubSendOperations(pool, strategies,
config.getSendTimeout());
}
@Override
@@ -63,6 +65,7 @@ public class IoTHubProducer extends DefaultProducer {
IoTHubDeliveryMode mode =
exchange.getIn().getHeader(IoTHubConstants.DELIVERY_MODE,
config.getDeliveryMode(), IoTHubDeliveryMode.class);
IotHubClientProtocol protocol = config.getProtocol();
+ checkProtocolSupportsDeliveryMode(protocol, mode);
if (ObjectHelper.isEmpty(deviceId)) {
throw new IllegalArgumentException(
@@ -79,6 +82,15 @@ public class IoTHubProducer extends DefaultProducer {
operations.send(deviceId, connectionString, protocol, mode, context);
}
+ private static void checkProtocolSupportsDeliveryMode(IotHubClientProtocol
protocol, IoTHubDeliveryMode mode) {
+ if (protocol == IotHubClientProtocol.HTTPS && mode !=
IoTHubDeliveryMode.TELEMETRY) {
+ // the Azure IoT SDK fails twin operations over HTTPS: say so
before opening a device client
+ throw new IllegalArgumentException(
+ "The delivery mode " + mode + " updates the device twin,
which the Azure IoT SDK supports only over"
+ + " MQTT, MQTT_WS, AMQPS and
AMQPS_WS, not over HTTPS");
+ }
+ }
+
/**
* Resolves the telemetry payload and twin properties for this exchange
based on the delivery mode.
*
diff --git
a/components/camel-azure/camel-azure-iothub/src/main/java/org/apache/camel/component/azure/iothub/client/DeviceClientPool.java
b/components/camel-azure/camel-azure-iothub/src/main/java/org/apache/camel/component/azure/iothub/client/DeviceClientPool.java
index f90c7a15f21b..635e1ad502e7 100644
---
a/components/camel-azure/camel-azure-iothub/src/main/java/org/apache/camel/component/azure/iothub/client/DeviceClientPool.java
+++
b/components/camel-azure/camel-azure-iothub/src/main/java/org/apache/camel/component/azure/iothub/client/DeviceClientPool.java
@@ -37,6 +37,7 @@ import com.microsoft.azure.sdk.iot.device.DeviceClient;
import com.microsoft.azure.sdk.iot.device.IotHubClientProtocol;
import com.microsoft.azure.sdk.iot.device.IotHubConnectionStatusChangeReason;
import com.microsoft.azure.sdk.iot.device.transport.IotHubConnectionStatus;
+import com.microsoft.azure.sdk.iot.device.twin.DesiredPropertiesCallback;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -51,9 +52,18 @@ import org.slf4j.LoggerFactory;
* callback, and disconnected clients are retired automatically; any in-use
client is closed only when the final lease
* is released. Callers may also remove a client from the pool explicitly
during cleanup.
* </p>
+ *
+ * <p>
+ * A client over HTTPS is kept apart from the client over MQTT or AMQPS of the
same device, as it cannot do twin
+ * operations. MQTT and AMQPS endpoints of a device share one client, as IoT
Hub allows only one MQTT or AMQP connection
+ * per device.
+ * </p>
*/
public class DeviceClientPool {
+ // the suffix of the pool key of a client over HTTPS; ':' separates the
parts of the identity
+ private static final String HTTPS_KEY_SUFFIX = "|HTTPS";
+
private static final Logger LOG =
LoggerFactory.getLogger(DeviceClientPool.class);
@FunctionalInterface
@@ -182,11 +192,17 @@ public class DeviceClientPool {
// package-private for test hooks only
DeviceClient getOrCreate(String deviceId, String connectionString,
IotHubClientProtocol protocol) {
+ return getOrCreate(deviceId, connectionString, protocol, null);
+ }
+
+ // package-private for test hooks only
+ DeviceClient getOrCreate(
+ String deviceId, String connectionString, IotHubClientProtocol
protocol, Duration subscribeTimeout) {
if (Thread.currentThread().isInterrupted() || shuttingDown.get()) {
throw new IllegalStateException("Skipping client creation due to
shutdown: " + deviceId);
}
- String poolKey = resolvePoolKey(deviceId, connectionString);
+ String poolKey = resolvePoolKey(deviceId, connectionString, protocol);
PooledClient existing = pool.get(poolKey);
if (existing != null) {
@@ -203,7 +219,7 @@ public class DeviceClientPool {
createdFuture.complete(rechecked.client);
return rechecked.client;
}
- DeviceClient client = createClient(deviceId, connectionString,
protocol);
+ DeviceClient client = createClient(deviceId, connectionString,
protocol, subscribeTimeout);
// read the clock after open: opening can take longer than the
idle timeout on a slow hub
PooledClient pooled = new PooledClient(client, nowMillis());
PooledClient previous = pool.putIfAbsent(poolKey, pooled);
@@ -252,11 +268,20 @@ public class DeviceClientPool {
}
public Lease acquire(String deviceId, String connectionString,
IotHubClientProtocol protocol) {
+ return acquire(deviceId, connectionString, protocol, null);
+ }
+
+ /**
+ * @param subscribeTimeout the timeout of the subscription to desired
properties when the device client is created,
+ * or null for the default of the Azure IoT SDK
+ */
+ public Lease acquire(
+ String deviceId, String connectionString, IotHubClientProtocol
protocol, Duration subscribeTimeout) {
if (Thread.currentThread().isInterrupted() || shuttingDown.get()) {
throw new IllegalStateException("Skipping client creation due to
shutdown: " + deviceId);
}
- String poolKey = resolvePoolKey(deviceId, connectionString);
+ String poolKey = resolvePoolKey(deviceId, connectionString, protocol);
for (;;) {
// read the clock on every attempt: getOrCreate below can block
for a whole open of the client
@@ -279,7 +304,7 @@ public class DeviceClientPool {
continue;
}
- DeviceClient client = getOrCreate(deviceId, connectionString,
protocol);
+ DeviceClient client = getOrCreate(deviceId, connectionString,
protocol, subscribeTimeout);
final long afterCreate = nowMillis();
AtomicReference<PooledClient> acquired = new AtomicReference<>();
pool.computeIfPresent(poolKey, (key, pooled) -> {
@@ -304,6 +329,11 @@ public class DeviceClientPool {
return acquire(deviceId, connectionString, protocol);
}
+ public Lease lease(
+ String deviceId, String connectionString, IotHubClientProtocol
protocol, Duration subscribeTimeout) {
+ return acquire(deviceId, connectionString, protocol, subscribeTimeout);
+ }
+
private boolean isCreationInProgress(String poolKey) {
return creationFutures.containsKey(poolKey);
}
@@ -321,7 +351,9 @@ public class DeviceClientPool {
}
void remove(String deviceId, String connectionString) {
- removePoolEntry(resolvePoolKey(deviceId, connectionString));
+ String poolKey = resolvePoolKey(deviceId, connectionString);
+ removePoolEntry(poolKey);
+ removePoolEntry(poolKey + HTTPS_KEY_SUFFIX);
}
void remove(String deviceId) {
@@ -369,6 +401,9 @@ public class DeviceClientPool {
if (poolKey == null) {
return false;
}
+ if (poolKey.endsWith(HTTPS_KEY_SUFFIX)) {
+ poolKey = poolKey.substring(0, poolKey.length() -
HTTPS_KEY_SUFFIX.length());
+ }
if (poolKey.equals(deviceId)) {
return true;
}
@@ -376,6 +411,11 @@ public class DeviceClientPool {
return parts.length >= 2 && parts[1].equals(deviceId);
}
+ private static String resolvePoolKey(String deviceId, String
connectionString, IotHubClientProtocol protocol) {
+ String poolKey = resolvePoolKey(deviceId, connectionString);
+ return protocol == IotHubClientProtocol.HTTPS ? poolKey +
HTTPS_KEY_SUFFIX : poolKey;
+ }
+
private static String resolvePoolKey(String deviceId, String
connectionString) {
if (deviceId == null || deviceId.isBlank()) {
return connectionString;
@@ -426,7 +466,8 @@ public class DeviceClientPool {
return !identity.isEmpty() ? identity.toString() : deviceId;
}
- private DeviceClient createClient(String deviceId, String
connectionString, IotHubClientProtocol protocol) {
+ private DeviceClient createClient(
+ String deviceId, String connectionString, IotHubClientProtocol
protocol, Duration subscribeTimeout) {
try {
DeviceClient client = deviceClientFactory.create(connectionString,
protocol);
if (shuttingDown.get()) {
@@ -441,13 +482,22 @@ public class DeviceClientPool {
try {
// Avoid duplicate desired-property subscriptions: subscribe
only if not already subscribed.
// The Azure DeviceClient does not expose a way to check, so
we rely on only subscribing once per client creation.
- client.subscribeToDesiredProperties((twinUpdate, ctx) -> {
- }, null);
+ // the Azure IoT SDK supports twin operations, such as this
subscription, only over MQTT and AMQPS:
+ // over HTTPS it throws UnsupportedOperationException, which
failed every send, also of telemetry
+ if (protocol != IotHubClientProtocol.HTTPS) {
+ DesiredPropertiesCallback callback = (twinUpdate, ctx) -> {
+ };
+ if (subscribeTimeout != null) {
+ client.subscribeToDesiredProperties(callback, null,
Math.toIntExact(subscribeTimeout.toMillis()));
+ } else {
+ client.subscribeToDesiredProperties(callback, null);
+ }
+ }
client.setConnectionStatusChangeCallback(context -> {
if (context == null) {
return;
}
- evictDisconnectedClient(deviceId, connectionString,
client, context);
+ evictDisconnectedClient(deviceId, connectionString,
protocol, client, context);
}, null);
} catch (Exception e) {
closeQuietly(deviceId, client, "subscription setup");
@@ -466,7 +516,7 @@ public class DeviceClientPool {
}
private void evictDisconnectedClient(
- String deviceId, String connectionString, DeviceClient client,
+ String deviceId, String connectionString, IotHubClientProtocol
protocol, DeviceClient client,
ConnectionStatusChangeContext context) {
if (context == null || shuttingDown.get()) {
return;
@@ -478,7 +528,7 @@ public class DeviceClientPool {
return;
}
- String poolKey = resolvePoolKey(deviceId, connectionString);
+ String poolKey = resolvePoolKey(deviceId, connectionString, protocol);
AtomicReference<PooledClient> removed = new AtomicReference<>();
pool.computeIfPresent(poolKey, (key, pooled) -> {
diff --git
a/components/camel-azure/camel-azure-iothub/src/main/java/org/apache/camel/component/azure/iothub/operations/IoTHubSendOperations.java
b/components/camel-azure/camel-azure-iothub/src/main/java/org/apache/camel/component/azure/iothub/operations/IoTHubSendOperations.java
index c10b8dcb145f..defe8cbbe55b 100644
---
a/components/camel-azure/camel-azure-iothub/src/main/java/org/apache/camel/component/azure/iothub/operations/IoTHubSendOperations.java
+++
b/components/camel-azure/camel-azure-iothub/src/main/java/org/apache/camel/component/azure/iothub/operations/IoTHubSendOperations.java
@@ -16,6 +16,7 @@
*/
package org.apache.camel.component.azure.iothub.operations;
+import java.time.Duration;
import java.util.List;
import com.microsoft.azure.sdk.iot.device.DeviceClient;
@@ -35,10 +36,20 @@ public class IoTHubSendOperations {
private final DeviceClientPool pool;
private final List<DeliveryStrategy> strategies;
+ private final Duration subscribeTimeout;
public IoTHubSendOperations(DeviceClientPool pool, List<DeliveryStrategy>
strategies) {
+ this(pool, strategies, null);
+ }
+
+ /**
+ * @param subscribeTimeout the timeout of the subscription to desired
properties when a device client is created, or
+ * null for the default of the Azure IoT SDK
+ */
+ public IoTHubSendOperations(DeviceClientPool pool, List<DeliveryStrategy>
strategies, Duration subscribeTimeout) {
this.pool = pool;
this.strategies = strategies;
+ this.subscribeTimeout = subscribeTimeout;
}
/**
@@ -56,7 +67,7 @@ public class IoTHubSendOperations {
throw new InterruptedException("Thread interrupted before dispatch
for device: " + deviceId);
}
- try (DeviceClientPool.Lease lease = pool.lease(deviceId,
connectionString, protocol)) {
+ try (DeviceClientPool.Lease lease = pool.lease(deviceId,
connectionString, protocol, subscribeTimeout)) {
DeviceClient client = lease.client();
executeStrategies(client, deviceId, context, mode);
} catch (Exception e) {
diff --git
a/components/camel-azure/camel-azure-iothub/src/main/java/org/apache/camel/component/azure/iothub/operations/TelemetryDeliveryStrategy.java
b/components/camel-azure/camel-azure-iothub/src/main/java/org/apache/camel/component/azure/iothub/operations/TelemetryDeliveryStrategy.java
index 241ca179fef9..e459fa786ca0 100644
---
a/components/camel-azure/camel-azure-iothub/src/main/java/org/apache/camel/component/azure/iothub/operations/TelemetryDeliveryStrategy.java
+++
b/components/camel-azure/camel-azure-iothub/src/main/java/org/apache/camel/component/azure/iothub/operations/TelemetryDeliveryStrategy.java
@@ -35,10 +35,19 @@ public class TelemetryDeliveryStrategy implements
DeliveryStrategy {
private static final Logger LOG =
LoggerFactory.getLogger(TelemetryDeliveryStrategy.class);
private final String contentType;
+ private final String contentEncoding;
private final Duration sendTimeout;
public TelemetryDeliveryStrategy(String contentType, Duration sendTimeout)
{
+ this(contentType, StandardCharsets.UTF_8.name(), sendTimeout);
+ }
+
+ /**
+ * @param contentEncoding the content encoding of the messages, or null or
empty to not set one
+ */
+ public TelemetryDeliveryStrategy(String contentType, String
contentEncoding, Duration sendTimeout) {
this.contentType = contentType;
+ this.contentEncoding = contentEncoding;
this.sendTimeout = sendTimeout;
}
@@ -53,7 +62,10 @@ public class TelemetryDeliveryStrategy implements
DeliveryStrategy {
Message msg = new Message(payload);
msg.setContentType(contentType);
- msg.setContentEncoding(StandardCharsets.UTF_8.name());
+ // a binary body is not text: an empty contentEncoding sends the
message without one
+ if (contentEncoding != null && !contentEncoding.isEmpty()) {
+ msg.setContentEncoding(contentEncoding);
+ }
msg.setMessageId(UUID.randomUUID().toString());
int timeoutMillis = Math.toIntExact(sendTimeout.toMillis());
diff --git
a/components/camel-azure/camel-azure-iothub/src/test/java/org/apache/camel/component/azure/iothub/IoTHubProducerProtocolOptionsTest.java
b/components/camel-azure/camel-azure-iothub/src/test/java/org/apache/camel/component/azure/iothub/IoTHubProducerProtocolOptionsTest.java
new file mode 100644
index 000000000000..bd8c98230763
--- /dev/null
+++
b/components/camel-azure/camel-azure-iothub/src/test/java/org/apache/camel/component/azure/iothub/IoTHubProducerProtocolOptionsTest.java
@@ -0,0 +1,196 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.azure.iothub;
+
+import java.nio.charset.StandardCharsets;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import com.microsoft.azure.sdk.iot.device.DeviceClient;
+import com.microsoft.azure.sdk.iot.device.IotHubClientProtocol;
+import com.microsoft.azure.sdk.iot.device.Message;
+import com.microsoft.azure.sdk.iot.device.twin.DesiredPropertiesCallback;
+import com.microsoft.azure.sdk.iot.device.twin.Twin;
+import com.microsoft.azure.sdk.iot.device.twin.TwinCollection;
+import org.apache.camel.Exchange;
+import org.apache.camel.Producer;
+import org.apache.camel.support.DefaultExchange;
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.ArgumentCaptor;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.ArgumentMatchers.isNull;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+/**
+ * The protocol, contentEncoding and sendTimeout options of the producer, with
a mocked DeviceClient that throws on the
+ * subscription to desired properties over HTTPS, as the Azure IoT SDK does.
+ */
+class IoTHubProducerProtocolOptionsTest extends CamelTestSupport {
+
+ private static final String CONNECTION_STRING =
"HostName=h;DeviceId=myDevice;SharedAccessKey=k";
+ private static final String TWIN_OVER_HTTPS
+ = "Twin operations are only supported over MQTT, MQTT_WS, AMQPS,
and AMQPS_WS";
+
+ // the device clients the pool created, a new mock for each
+ private final List<DeviceClient> created = new CopyOnWriteArrayList<>();
+ private DeviceClient client;
+
+ @BeforeEach
+ void mockDeviceClient() throws Exception {
+ IoTHubComponent component = context.getComponent("azure-iothub",
IoTHubComponent.class);
+ component.getOrCreateClientPool().setDeviceClientFactory((cs,
protocol) -> {
+ DeviceClient mock = mock(DeviceClient.class);
+ if (protocol == IotHubClientProtocol.HTTPS) {
+ doThrow(new
UnsupportedOperationException(TWIN_OVER_HTTPS)).when(mock)
+
.subscribeToDesiredProperties(any(DesiredPropertiesCallback.class), any());
+ doThrow(new
UnsupportedOperationException(TWIN_OVER_HTTPS)).when(mock)
+
.subscribeToDesiredProperties(any(DesiredPropertiesCallback.class), any(),
anyInt());
+ doThrow(new
UnsupportedOperationException(TWIN_OVER_HTTPS)).when(mock).getTwin(anyInt());
+ } else {
+ Twin twin = mock(Twin.class);
+ when(twin.getReportedProperties()).thenReturn(new
TwinCollection());
+ when(mock.getTwin(anyInt())).thenReturn(twin);
+ }
+ created.add(mock);
+ client = mock;
+ return mock;
+ });
+ }
+
+ private Exchange send(String options, Object body) throws Exception {
+ return send(options, body, null);
+ }
+
+ private Exchange send(String options, Object body, IoTHubDeliveryMode
modeHeader) throws Exception {
+ Producer producer = createProducer(options);
+ producer.start();
+ try {
+ Exchange exchange = new DefaultExchange(context);
+ exchange.getIn().setBody(body);
+ if (modeHeader != null) {
+ exchange.getIn().setHeader(IoTHubConstants.DELIVERY_MODE,
modeHeader);
+ }
+ producer.process(exchange);
+ return exchange;
+ } finally {
+ producer.stop();
+ }
+ }
+
+ private Producer createProducer(String options) throws Exception {
+ return context.getEndpoint("azure-iothub:myDevice?connectionString=" +
CONNECTION_STRING + options).createProducer();
+ }
+
+ private Message sentMessage() throws Exception {
+ ArgumentCaptor<Message> message =
ArgumentCaptor.forClass(Message.class);
+ verify(client).sendEvent(message.capture(), anyInt());
+ return message.getValue();
+ }
+
+ @Test
+ void telemetryIsSentOverHttps() throws Exception {
+ // failed with "DeviceClient creation failed", as the subscription to
desired properties threw
+ send("&protocol=HTTPS",
"{\"temperature\":21}".getBytes(StandardCharsets.UTF_8));
+
+ assertEquals("{\"temperature\":21}", new
String(sentMessage().getBytes(), StandardCharsets.UTF_8));
+ }
+
+ @Test
+ void aTwinEndpointOverHttpsFailsToStart() throws Exception {
+ for (String mode : List.of("TWIN", "BOTH")) {
+ Producer producer = createProducer("&protocol=HTTPS&deliveryMode="
+ mode);
+
+ IllegalArgumentException e =
assertThrows(IllegalArgumentException.class, producer::start);
+
+ assertTrue(e.getMessage().contains("not over HTTPS"),
e.getMessage());
+ }
+ assertEquals(0, created.size(), "no device client should be opened");
+ }
+
+ @Test
+ void aTwinDeliveryModeHeaderOverHttpsFailsNamingTheProtocols() {
+ IllegalArgumentException e =
assertThrows(IllegalArgumentException.class,
+ () -> send("&protocol=HTTPS", Map.of("firmware", "1.0"),
IoTHubDeliveryMode.TWIN));
+
+ assertTrue(e.getMessage().contains("not over HTTPS"), e.getMessage());
+ assertEquals(0, created.size(), "no device client should be opened");
+ }
+
+ @Test
+ void anHttpsClientIsNotReusedForATwinUpdateOverMqtt() throws Exception {
+ send("&protocol=HTTPS",
"{\"temperature\":21}".getBytes(StandardCharsets.UTF_8));
+ // failed with the UnsupportedOperationException of the SDK: the MQTT
endpoint got the pooled HTTPS client
+ send("&deliveryMode=TWIN", Map.of("firmware", "1.0"));
+
+ assertEquals(2, created.size(), "the MQTT endpoint reused the device
client of the HTTPS endpoint");
+
verify(created.get(1)).updateReportedProperties(any(TwinCollection.class),
anyInt());
+ }
+
+ @Test
+ void mqttAndAmqpsShareOneClient() throws Exception {
+ // IoT Hub allows one MQTT or AMQP connection per device: a second
client would disconnect the first
+ send("", "{}".getBytes(StandardCharsets.UTF_8));
+ send("&protocol=AMQPS", "{}".getBytes(StandardCharsets.UTF_8));
+
+ assertEquals(1, created.size());
+ }
+
+ @Test
+ void sendTimeoutLimitsTheSubscriptionToDesiredProperties() throws
Exception {
+ send("&sendTimeout=3s", "{}".getBytes(StandardCharsets.UTF_8));
+
+ // failed on main: the subscription used the SDK default timeout
+
verify(client).subscribeToDesiredProperties(any(DesiredPropertiesCallback.class),
isNull(), eq(3000));
+ verify(client,
never()).subscribeToDesiredProperties(any(DesiredPropertiesCallback.class),
any());
+ }
+
+ @Test
+ void contentEncodingIsUtf8ByDefault() throws Exception {
+ send("", "{}".getBytes(StandardCharsets.UTF_8));
+
+ assertEquals("UTF-8", sentMessage().getContentEncoding());
+ }
+
+ @Test
+ void contentEncodingCanBeChanged() throws Exception {
+ send("&contentEncoding=UTF-16",
"{}".getBytes(StandardCharsets.UTF_16));
+
+ assertEquals("UTF-16", sentMessage().getContentEncoding());
+ }
+
+ @Test
+ void emptyContentEncodingSendsNone() throws Exception {
+ // a binary body was always labeled as UTF-8 text
+ send("&contentType=application/octet-stream&contentEncoding=", new
byte[] { 1, 2, 3 });
+
+ assertNull(sentMessage().getContentEncoding());
+ }
+}
diff --git
a/components/camel-azure/camel-azure-iothub/src/test/java/org/apache/camel/component/azure/iothub/client/DeviceClientPoolTest.java
b/components/camel-azure/camel-azure-iothub/src/test/java/org/apache/camel/component/azure/iothub/client/DeviceClientPoolTest.java
index 057014a278b3..646218ea866d 100644
---
a/components/camel-azure/camel-azure-iothub/src/test/java/org/apache/camel/component/azure/iothub/client/DeviceClientPoolTest.java
+++
b/components/camel-azure/camel-azure-iothub/src/test/java/org/apache/camel/component/azure/iothub/client/DeviceClientPoolTest.java
@@ -168,6 +168,26 @@ class DeviceClientPoolTest {
verify(client, times(1)).close();
}
+ @Test
+ void testHttpsClientIsKeptApartAndRemovedByDeviceId() throws Exception {
+ DeviceClient https = mock(DeviceClient.class);
+ DeviceClient mqtt = mock(DeviceClient.class);
+ DeviceClientPool pool = new DeviceClientPool(Duration.ofMinutes(5),
Duration.ofSeconds(30));
+ pool.setDeviceClientFactory((cs, protocol) -> protocol ==
IotHubClientProtocol.HTTPS ? https : mqtt);
+
+ assertSame(https, pool.getOrCreate("d", CS,
IotHubClientProtocol.HTTPS));
+ assertSame(mqtt, pool.getOrCreate("d", CS, IotHubClientProtocol.MQTT));
+ assertSame(mqtt, pool.getOrCreate("d", CS,
IotHubClientProtocol.AMQPS));
+ assertEquals(2, pool.getActiveClientCount());
+
+ pool.remove("d");
+ pool.remove("d");
+
+ assertEquals(0, pool.getActiveClientCount());
+ verify(https, times(1)).close();
+ verify(mqtt, times(1)).close();
+ }
+
@Test
void testShutdownClosesAllAndBlocksCreation() throws Exception {
DeviceClient client = mock(DeviceClient.class);
diff --git
a/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/AzureIothubComponentBuilderFactory.java
b/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/AzureIothubComponentBuilderFactory.java
index af536e660101..0a56df3ab2f1 100644
---
a/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/AzureIothubComponentBuilderFactory.java
+++
b/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/AzureIothubComponentBuilderFactory.java
@@ -70,10 +70,29 @@ public interface AzureIothubComponentBuilderFactory {
}
+ /**
+ * Content encoding applied to telemetry messages. Set it to an empty
+ * value to send telemetry without a content encoding, for example for
a
+ * binary body such as Avro or Protobuf.
+ *
+ * The option is a: <code>java.lang.String</code> type.
+ *
+ * Default: UTF-8
+ * Group: producer
+ *
+ * @param contentEncoding the value to set
+ * @return the dsl builder
+ */
+ default AzureIothubComponentBuilder contentEncoding(java.lang.String
contentEncoding) {
+ doSetProperty("contentEncoding", contentEncoding);
+ return this;
+ }
+
+
/**
* The content type of the telemetry message, which IoT Hub message
- * routing needs to query the body. The producer always sets the
content
- * encoding to UTF-8.
+ * routing needs to query the body. The contentEncoding option sets the
+ * content encoding.
*
* The option is a: <code>java.lang.String</code> type.
*
@@ -157,8 +176,10 @@ public interface AzureIothubComponentBuilderFactory {
/**
* How long the producer waits for IoT Hub to acknowledge a telemetry
- * message, and for each device twin request: getting the twin and
- * updating its reported properties.
+ * message, and for each device twin request: getting the twin,
updating
+ * its reported properties, and the subscription to desired properties
+ * when a device client is created. Opening the device client uses the
+ * retry policy of the Azure IoT SDK and is not limited by this
timeout.
*
* The option is a: <code>java.time.Duration</code> type.
*
@@ -236,8 +257,9 @@ public interface AzureIothubComponentBuilderFactory {
/**
* The connection string of the device, with its HostName, DeviceId and
* SharedAccessKey. The producer opens one device client per hub,
device
- * and module of the connection string, and reuses it. The
- * CamelAzureIoTHubConnectionString header replaces this option.
+ * and module of the connection string, and reuses it; an HTTPS
endpoint
+ * uses a client of its own. The CamelAzureIoTHubConnectionString
header
+ * replaces this option.
*
* The option is a: <code>java.lang.String</code> type.
*
@@ -272,6 +294,7 @@ public interface AzureIothubComponentBuilderFactory {
Object value) {
switch (name) {
case "configuration": ((IoTHubComponent)
component).setConfiguration((org.apache.camel.component.azure.iothub.IoTHubConfiguration)
value); return true;
+ case "contentEncoding": getOrCreateConfiguration((IoTHubComponent)
component).setContentEncoding((java.lang.String) value); return true;
case "contentType": getOrCreateConfiguration((IoTHubComponent)
component).setContentType((java.lang.String) value); return true;
case "deliveryMode": getOrCreateConfiguration((IoTHubComponent)
component).setDeliveryMode((org.apache.camel.component.azure.iothub.IoTHubDeliveryMode)
value); return true;
case "lazyStartProducer": ((IoTHubComponent)
component).setLazyStartProducer((boolean) value); return true;
diff --git
a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/IoTHubEndpointBuilderFactory.java
b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/IoTHubEndpointBuilderFactory.java
index ea370a383f21..e6711c44dc98 100644
---
a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/IoTHubEndpointBuilderFactory.java
+++
b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/IoTHubEndpointBuilderFactory.java
@@ -45,10 +45,27 @@ public interface IoTHubEndpointBuilderFactory {
return (AdvancedIoTHubEndpointBuilder) this;
}
+ /**
+ * Content encoding applied to telemetry messages. Set it to an empty
+ * value to send telemetry without a content encoding, for example for
a
+ * binary body such as Avro or Protobuf.
+ *
+ * The option is a: <code>java.lang.String</code> type.
+ *
+ * Default: UTF-8
+ * Group: producer
+ *
+ * @param contentEncoding the value to set
+ * @return the dsl builder
+ */
+ default IoTHubEndpointBuilder contentEncoding(String contentEncoding) {
+ doSetProperty("contentEncoding", contentEncoding);
+ return this;
+ }
/**
* The content type of the telemetry message, which IoT Hub message
- * routing needs to query the body. The producer always sets the
content
- * encoding to UTF-8.
+ * routing needs to query the body. The contentEncoding option sets the
+ * content encoding.
*
* The option is a: <code>java.lang.String</code> type.
*
@@ -140,8 +157,10 @@ public interface IoTHubEndpointBuilderFactory {
}
/**
* How long the producer waits for IoT Hub to acknowledge a telemetry
- * message, and for each device twin request: getting the twin and
- * updating its reported properties.
+ * message, and for each device twin request: getting the twin,
updating
+ * its reported properties, and the subscription to desired properties
+ * when a device client is created. Opening the device client uses the
+ * retry policy of the Azure IoT SDK and is not limited by this
timeout.
*
* The option is a: <code>java.time.Duration</code> type.
*
@@ -157,8 +176,10 @@ public interface IoTHubEndpointBuilderFactory {
}
/**
* How long the producer waits for IoT Hub to acknowledge a telemetry
- * message, and for each device twin request: getting the twin and
- * updating its reported properties.
+ * message, and for each device twin request: getting the twin,
updating
+ * its reported properties, and the subscription to desired properties
+ * when a device client is created. Opening the device client uses the
+ * retry policy of the Azure IoT SDK and is not limited by this
timeout.
*
* The option will be converted to a <code>java.time.Duration</code>
* type.
@@ -176,8 +197,9 @@ public interface IoTHubEndpointBuilderFactory {
/**
* The connection string of the device, with its HostName, DeviceId and
* SharedAccessKey. The producer opens one device client per hub,
device
- * and module of the connection string, and reuses it. The
- * CamelAzureIoTHubConnectionString header replaces this option.
+ * and module of the connection string, and reuses it; an HTTPS
endpoint
+ * uses a client of its own. The CamelAzureIoTHubConnectionString
header
+ * replaces this option.
*
* The option is a: <code>java.lang.String</code> type.
*