Skip to content

Commit 2d221f3

Browse files
authored
[#2026] Adding config property HONO_MQTT_SEND_MESSAGE_TO_DEVICE_TIMEOUT
Adding a new configuration property for MQTT adapter called "HONO_MQTT_SEND_MESSAGE_TO_DEVICE_TIMEOUT" which will replace the current "HONO_MQTT_COMMAND_ACK_TIMEOUT" property. This is done in order to provide an abstraction for the configuration of protocols using a bidirectional connection (i.e. MQTT and AMQP). This fixes #2026 Signed-off-by: Florian Kaltner <[email protected]>
1 parent bf59ed6 commit 2d221f3

File tree

6 files changed

+87
-12
lines changed

6 files changed

+87
-12
lines changed

Diff for: adapters/amqp-vertx/src/main/java/org/eclipse/hono/adapter/amqp/AmqpAdapterProperties.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class AmqpAdapterProperties extends ProtocolAdapterProperties {
3838
*/
3939
public static final int DEFAULT_IDLE_TIMEOUT_MILLIS = 60_000;
4040
/**
41-
* The amount of time (in milliseconds) to wait for a device to acknowledge receiving a command message.
41+
* The amount of time (in milliseconds) to wait for a device to acknowledge receiving a command message.
4242
*/
4343
public static final long DEFAULT_SEND_MESSAGE_TO_DEVICE_TIMEOUT = 1000L; // ms
4444

Diff for: adapters/mqtt-vertx-base/src/main/java/org/eclipse/hono/adapter/mqtt/CommandSubscriptionsManager.java

+9-4
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ public void handlePubAck(final Integer msgId) {
7272
Objects.requireNonNull(msgId);
7373
LOG.trace("Acknowledgement received for command [Msg-id: {}] that has been sent to device", msgId);
7474
Optional.ofNullable(removeFromWaitingForAcknowledgement(msgId)).ifPresent(value -> {
75-
cancelTimer(value.timerId);
75+
if (value.timerId != null) {
76+
cancelTimer(value.timerId);
77+
}
7678
value.onAckHandler.handle(msgId);
7779
});
7880
}
@@ -193,9 +195,12 @@ private Future<Void> closeCommandConsumer(final CommandSubscription subscription
193195
});
194196
}
195197

196-
private long startTimer(final Integer msgId) {
198+
private Long startTimer(final Integer msgId) {
199+
if (config.getEffectiveSendMessageToDeviceTimeout() < 1) {
200+
return null;
201+
}
197202

198-
return vertx.setTimer(config.getCommandAckTimeout(), timerId -> {
203+
return vertx.setTimer(config.getEffectiveSendMessageToDeviceTimeout(), timerId -> {
199204
Optional.ofNullable(removeFromWaitingForAcknowledgement(msgId))
200205
.ifPresent(value -> value.onAckTimeoutHandler.handle(null));
201206
});
@@ -218,7 +223,7 @@ private static class PendingCommandRequest {
218223

219224
private PendingCommandRequest(final Long timerId, final Handler<Integer> onAckHandler,
220225
final Handler<Void> onAckTimeoutHandler) {
221-
this.timerId = Objects.requireNonNull(timerId);
226+
this.timerId = timerId;
222227
this.onAckHandler = Objects.requireNonNull(onAckHandler);
223228
this.onAckTimeoutHandler = Objects.requireNonNull(onAckTimeoutHandler);
224229
}

Diff for: adapters/mqtt-vertx-base/src/main/java/org/eclipse/hono/adapter/mqtt/MqttProtocolAdapterProperties.java

+69-6
Original file line numberDiff line numberDiff line change
@@ -25,37 +25,100 @@ public class MqttProtocolAdapterProperties extends ProtocolAdapterProperties {
2525
* The default number of milliseconds to wait for PUBACK.
2626
*/
2727
protected static final int DEFAULT_COMMAND_ACK_TIMEOUT = 100;
28+
/**
29+
* The amount of time (in milliseconds) to wait for a device to acknowledge receiving a command message.
30+
*/
31+
protected static final long DEFAULT_SEND_MESSAGE_TO_DEVICE_TIMEOUT = 1000L; // ms
32+
2833
private int commandAckTimeout = DEFAULT_COMMAND_ACK_TIMEOUT;
34+
private long sendMessageToDeviceTimeout = DEFAULT_SEND_MESSAGE_TO_DEVICE_TIMEOUT;
2935

3036
/**
31-
* Gets the waiting for acknowledgement time out in milliseconds for commands published with QoS 1.
37+
* Gets the waiting for acknowledgement timeout in milliseconds for commands published with QoS 1.
3238
* <p>
33-
* This time out is used by the MQTT adapter for commands published with QoS 1. If there is no acknowledgement
39+
* This timeout is used by the MQTT adapter for commands published with QoS 1. If there is no acknowledgement
3440
* within this time limit, then the command is settled with the <em>released</em> outcome.
3541
* <p>
3642
* The default value is {@link #DEFAULT_COMMAND_ACK_TIMEOUT}.
3743
*
38-
* @return The time out in milliseconds.
44+
* @deprecated Use {@link #getSendMessageToDeviceTimeout()} instead.
45+
*
46+
* @return The timeout in milliseconds.
3947
*/
48+
@Deprecated(forRemoval = true)
4049
public final int getCommandAckTimeout() {
4150
return commandAckTimeout;
4251
}
4352

4453
/**
45-
* Sets the waiting for acknowledgement time out in milliseconds for commands published with QoS 1.
54+
* Sets the waiting for acknowledgement timeout in milliseconds for commands published with QoS 1.
4655
* <p>
47-
* This time out is used by the MQTT adapter for commands published with QoS 1. If there is no acknowledgement
56+
* This timeout is used by the MQTT adapter for commands published with QoS 1. If there is no acknowledgement
4857
* within this time limit, then the command is settled with the <em>released</em> outcome.
4958
* <p>
5059
* The default value is {@link #DEFAULT_COMMAND_ACK_TIMEOUT}.
5160
*
52-
* @param timeout The time out in milliseconds.
61+
* @deprecated Use {@link #setSendMessageToDeviceTimeout(long)} ()} instead.
62+
*
63+
* @param timeout The timeout in milliseconds.
5364
* @throws IllegalArgumentException if the timeout is negative.
5465
*/
66+
@Deprecated(forRemoval = true)
5567
public final void setCommandAckTimeout(final int timeout) {
5668
if (timeout < 0) {
5769
throw new IllegalArgumentException("timeout must not be negative");
5870
}
5971
this.commandAckTimeout = timeout;
6072
}
73+
74+
/**
75+
* Gets the waiting for acknowledgement timeout in milliseconds for commands published with QoS 1.
76+
* <p>
77+
* This timeout is used by the MQTT adapter for commands published with QoS 1. If there is no acknowledgement
78+
* within this time limit, then the command is settled with the <em>released</em> outcome.
79+
* <p>
80+
* The default value of this property is {@link #DEFAULT_SEND_MESSAGE_TO_DEVICE_TIMEOUT}.
81+
*
82+
* @return The timeout in milliseconds.
83+
*/
84+
public long getSendMessageToDeviceTimeout() {
85+
return sendMessageToDeviceTimeout;
86+
}
87+
88+
/**
89+
* Sets the waiting for acknowledgement timeout in milliseconds for commands published with QoS 1.
90+
* <p>
91+
* This timeout is used by the MQTT adapter for commands published with QoS 1. If there is no acknowledgement
92+
* within this time limit, then the command is settled with the <em>released</em> outcome.
93+
* <p>
94+
* The default value of this property is {@link #DEFAULT_SEND_MESSAGE_TO_DEVICE_TIMEOUT}.
95+
*
96+
* @param sendMessageToDeviceTimeout The timeout in milliseconds.
97+
* @throws IllegalArgumentException if the timeout is negative.
98+
*/
99+
public void setSendMessageToDeviceTimeout(final long sendMessageToDeviceTimeout) {
100+
if (sendMessageToDeviceTimeout < 0) {
101+
throw new IllegalArgumentException("timeout must not be negative");
102+
}
103+
104+
this.sendMessageToDeviceTimeout = sendMessageToDeviceTimeout;
105+
}
106+
107+
/**
108+
* Gets the effective timeout for waiting for acknowledgement in milliseconds for commands published with QoS 1
109+
* by taking the {@link #sendMessageToDeviceTimeout} and {@link #commandAckTimeout} properties into account.
110+
*
111+
* Can be removed when the deprecated {@link #commandAckTimeout} property is removed.
112+
*
113+
* @return The timeout in milliseconds.
114+
*/
115+
long getEffectiveSendMessageToDeviceTimeout() {
116+
if (sendMessageToDeviceTimeout == DEFAULT_SEND_MESSAGE_TO_DEVICE_TIMEOUT
117+
&& commandAckTimeout != DEFAULT_COMMAND_ACK_TIMEOUT) {
118+
return commandAckTimeout;
119+
} else {
120+
return sendMessageToDeviceTimeout;
121+
}
122+
}
123+
61124
}

Diff for: site/documentation/content/admin-guide/kura-adapter-config.md

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ The following table provides an overview of the configuration variables and corr
4444
| `HONO_KURA_PORT`<br>`--hono.kura.port` | no | `8883` | The secure port that the protocol adapter should listen on.<br>See [Port Configuration]({{< relref "#port-configuration" >}}) below for details. |
4545
| `HONO_KURA_SECURE_PROTOCOLS`<br>`--hono.kura.secureProtocols` | no | `TLSv1.2` | A (comma separated) list of secure protocols that are supported when negotiating TLS sessions. Please refer to the [vert.x documentation](https://vertx.io/docs/vertx-core/java/#ssl) for a list of supported protocol names. |
4646
| `HONO_KURA_TENANT_IDLE_TIMEOUT`<br>`--hono.kura.tenantIdleTimeout` | no | `0ms` | The duration after which the protocol adapter removes local state of the tenant (e.g. open AMQP links) with an amount and a unit, e.g. `2h` for 2 hours. See the [Spring Boot documentation](https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-external-config-conversion-duration) for an explanation of the format. The value `0ms` disables the timeout. |
47+
| `HONO_KURA_SEND_MESSAGE_TO_DEVICE_TIMEOUT`<br>`--hono.kura.sendMessageToDeviceTimeout` | no | `1000` | The amount of time (milliseconds) after which the sending of a command to a device using QoS 1 is considered to be failed. The value of this variable should be increased in cases where devices are connected over a network with high latency. |
4748

4849
The variables only need to be set if the default values do not match your environment.
4950

Diff for: site/documentation/content/admin-guide/mqtt-adapter-config.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ The following table provides an overview of the configuration variables and corr
2727
| `HONO_MQTT_AUTHENTICATION_REQUIRED`<br>`--hono.mqtt.authenticationRequired` | no | `true` | If set to `true` the protocol adapter requires devices to authenticate when connecting to the adapter. The credentials provided by the device are verified using the configured [Credentials Service]({{< relref "#credentials-service-connection-configuration" >}}). Devices that have failed to authenticate are not allowed to publish any data. |
2828
| `HONO_MQTT_BIND_ADDRESS`<br>`--hono.mqtt.bindAddress` | no | `127.0.0.1` | The IP address of the network interface that the secure port should be bound to.<br>See [Port Configuration]({{< relref "#port-configuration" >}}) below for details. |
2929
| `HONO_MQTT_CERT_PATH`<br>`--hono.mqtt.certPath` | no | - | The absolute path to the PEM file containing the certificate that the protocol adapter should use for authenticating to clients. This option must be used in conjunction with `HONO_MQTT_KEY_PATH`.<br>Alternatively, the `HONO_MQTT_KEY_STORE_PATH` option can be used to configure a key store containing both the key as well as the certificate. |
30-
| `HONO_MQTT_COMMAND_ACK_TIMEOUT`<br>`--hono.mqtt.commandAckTimeout` | no | `100` | The amount of time (milliseconds) after which the sending of a command to a device using QoS 1 is considered to be failed. The value of this variable should be increased in cases where devices are connected over a network with high latency. |
30+
| `HONO_MQTT_COMMAND_ACK_TIMEOUT`<br>`--hono.mqtt.commandAckTimeout` | no | `100` | Deprecated. Use `HONO_MQTT_SEND_MESSAGE_TO_DEVICE_TIMEOUT` instead. The amount of time (milliseconds) after which the sending of a command to a device using QoS 1 is considered to be failed. The value of this variable should be increased in cases where devices are connected over a network with high latency. |
31+
| `HONO_MQTT_SEND_MESSAGE_TO_DEVICE_TIMEOUT`<br>`--hono.mqtt.sendMessageToDeviceTimeout` | no | `1000` | The amount of time (milliseconds) after which the sending of a command to a device using QoS 1 is considered to be failed. The value of this variable should be increased in cases where devices are connected over a network with high latency. |
3132
| `HONO_MQTT_DEFAULTS_ENABLED`<br>`--hono.mqtt.defaultsEnabled` | no | `true` | If set to `true` the protocol adapter uses *default values* registered for a device to augment messages published by the device with missing information like a content type. In particular, the protocol adapter adds default values registered for the device as (application) properties with the same name to the AMQP 1.0 messages it sends downstream to the AMQP Messaging Network. |
3233
| `HONO_MQTT_INSECURE_PORT_BIND_ADDRESS`<br>`--hono.mqtt.insecurePortBindAddress` | no | `127.0.0.1` | The IP address of the network interface that the insecure port should be bound to.<br>See [Port Configuration]({{< relref "#port-configuration" >}}) below for details. |
3334
| `HONO_MQTT_INSECURE_PORT_ENABLED`<br>`--hono.mqtt.insecurePortEnabled` | no | `false` | If set to `true` the protocol adapter will open an insecure port (not secured by TLS) using either the port number set via `HONO_MQTT_INSECURE_PORT` or the default MQTT port number (`1883`) if not set explicitly.<br>See [Port Configuration]({{< relref "#port-configuration" >}}) below for details. |

Diff for: site/homepage/content/release-notes.md

+5
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ title = "Release Notes"
7878
because the Device Registration API does not define a corresponding operation.
7979
Consequently, the C&C functionality of the Kerlink Lora provider which relied on the *get*
8080
method has been removed.
81+
82+
### Deprecations
83+
84+
* The configuration property `HONO_MQTT_COMMAND_ACK_TIMEOUT` of the MQTT adapter is now deprecated
85+
and planned to be removed in a future release. Use `HONO_MQTT_SEND_MESSAGE_TO_DEVICE_TIMEOUT` instead.
8186

8287
## 1.2.3
8388

0 commit comments

Comments
 (0)