Add keep_alive_interval config for MQTT.

In case there is a loadbalancer between ChirpStack and the MQTT broker,
it is useful to have control over the keep-alive messages, to make sure
that the loadbalancer does not drop the connection if there is no
activity. In such a case you want to set the keep_alive_interval to a
lower interval than the loadbalancer timeout.
This commit is contained in:
Orne Brocaar 2022-11-25 12:51:35 +00:00
parent 3a6e359ce1
commit 948ed00b60
43 changed files with 267 additions and 3 deletions

View File

@ -66,6 +66,12 @@
# a random id will be generated by ChirpStack. # a random id will be generated by ChirpStack.
client_id="" client_id=""
# Keep alive interval.
#
# This defines the maximum time that that should pass without communication
# between the client and server.
keep_alive_interval="30s"
# CA certificate file (optional) # CA certificate file (optional)
# #
# Use this when setting up a secure connection (when server uses ssl://...) # Use this when setting up a secure connection (when server uses ssl://...)

View File

@ -66,6 +66,12 @@
# a random id will be generated by ChirpStack. # a random id will be generated by ChirpStack.
client_id="" client_id=""
# Keep alive interval.
#
# This defines the maximum time that that should pass without communication
# between the client and server.
keep_alive_interval="30s"
# CA certificate file (optional) # CA certificate file (optional)
# #
# Use this when setting up a secure connection (when server uses ssl://...) # Use this when setting up a secure connection (when server uses ssl://...)

View File

@ -66,6 +66,12 @@
# a random id will be generated by ChirpStack. # a random id will be generated by ChirpStack.
client_id="" client_id=""
# Keep alive interval.
#
# This defines the maximum time that that should pass without communication
# between the client and server.
keep_alive_interval="30s"
# CA certificate file (optional) # CA certificate file (optional)
# #
# Use this when setting up a secure connection (when server uses ssl://...) # Use this when setting up a secure connection (when server uses ssl://...)

View File

@ -66,6 +66,12 @@
# a random id will be generated by ChirpStack. # a random id will be generated by ChirpStack.
client_id="" client_id=""
# Keep alive interval.
#
# This defines the maximum time that that should pass without communication
# between the client and server.
keep_alive_interval="30s"
# CA certificate file (optional) # CA certificate file (optional)
# #
# Use this when setting up a secure connection (when server uses ssl://...) # Use this when setting up a secure connection (when server uses ssl://...)

View File

@ -66,6 +66,12 @@
# a random id will be generated by ChirpStack. # a random id will be generated by ChirpStack.
client_id="" client_id=""
# Keep alive interval.
#
# This defines the maximum time that that should pass without communication
# between the client and server.
keep_alive_interval="30s"
# CA certificate file (optional) # CA certificate file (optional)
# #
# Use this when setting up a secure connection (when server uses ssl://...) # Use this when setting up a secure connection (when server uses ssl://...)

View File

@ -66,6 +66,12 @@
# a random id will be generated by ChirpStack. # a random id will be generated by ChirpStack.
client_id="" client_id=""
# Keep alive interval.
#
# This defines the maximum time that that should pass without communication
# between the client and server.
keep_alive_interval="30s"
# CA certificate file (optional) # CA certificate file (optional)
# #
# Use this when setting up a secure connection (when server uses ssl://...) # Use this when setting up a secure connection (when server uses ssl://...)

View File

@ -66,6 +66,12 @@
# a random id will be generated by ChirpStack. # a random id will be generated by ChirpStack.
client_id="" client_id=""
# Keep alive interval.
#
# This defines the maximum time that that should pass without communication
# between the client and server.
keep_alive_interval="30s"
# CA certificate file (optional) # CA certificate file (optional)
# #
# Use this when setting up a secure connection (when server uses ssl://...) # Use this when setting up a secure connection (when server uses ssl://...)

View File

@ -66,6 +66,12 @@
# a random id will be generated by ChirpStack. # a random id will be generated by ChirpStack.
client_id="" client_id=""
# Keep alive interval.
#
# This defines the maximum time that that should pass without communication
# between the client and server.
keep_alive_interval="30s"
# CA certificate file (optional) # CA certificate file (optional)
# #
# Use this when setting up a secure connection (when server uses ssl://...) # Use this when setting up a secure connection (when server uses ssl://...)

View File

@ -66,6 +66,12 @@
# a random id will be generated by ChirpStack. # a random id will be generated by ChirpStack.
client_id="" client_id=""
# Keep alive interval.
#
# This defines the maximum time that that should pass without communication
# between the client and server.
keep_alive_interval="30s"
# CA certificate file (optional) # CA certificate file (optional)
# #
# Use this when setting up a secure connection (when server uses ssl://...) # Use this when setting up a secure connection (when server uses ssl://...)

View File

@ -66,6 +66,12 @@
# a random id will be generated by ChirpStack. # a random id will be generated by ChirpStack.
client_id="" client_id=""
# Keep alive interval.
#
# This defines the maximum time that that should pass without communication
# between the client and server.
keep_alive_interval="30s"
# CA certificate file (optional) # CA certificate file (optional)
# #
# Use this when setting up a secure connection (when server uses ssl://...) # Use this when setting up a secure connection (when server uses ssl://...)

View File

@ -66,6 +66,12 @@
# a random id will be generated by ChirpStack. # a random id will be generated by ChirpStack.
client_id="" client_id=""
# Keep alive interval.
#
# This defines the maximum time that that should pass without communication
# between the client and server.
keep_alive_interval="30s"
# CA certificate file (optional) # CA certificate file (optional)
# #
# Use this when setting up a secure connection (when server uses ssl://...) # Use this when setting up a secure connection (when server uses ssl://...)

View File

@ -66,6 +66,12 @@
# a random id will be generated by ChirpStack. # a random id will be generated by ChirpStack.
client_id="" client_id=""
# Keep alive interval.
#
# This defines the maximum time that that should pass without communication
# between the client and server.
keep_alive_interval="30s"
# CA certificate file (optional) # CA certificate file (optional)
# #
# Use this when setting up a secure connection (when server uses ssl://...) # Use this when setting up a secure connection (when server uses ssl://...)

View File

@ -66,6 +66,12 @@
# a random id will be generated by ChirpStack. # a random id will be generated by ChirpStack.
client_id="" client_id=""
# Keep alive interval.
#
# This defines the maximum time that that should pass without communication
# between the client and server.
keep_alive_interval="30s"
# CA certificate file (optional) # CA certificate file (optional)
# #
# Use this when setting up a secure connection (when server uses ssl://...) # Use this when setting up a secure connection (when server uses ssl://...)

View File

@ -66,6 +66,12 @@
# a random id will be generated by ChirpStack. # a random id will be generated by ChirpStack.
client_id="" client_id=""
# Keep alive interval.
#
# This defines the maximum time that that should pass without communication
# between the client and server.
keep_alive_interval="30s"
# CA certificate file (optional) # CA certificate file (optional)
# #
# Use this when setting up a secure connection (when server uses ssl://...) # Use this when setting up a secure connection (when server uses ssl://...)

View File

@ -66,6 +66,12 @@
# a random id will be generated by ChirpStack. # a random id will be generated by ChirpStack.
client_id="" client_id=""
# Keep alive interval.
#
# This defines the maximum time that that should pass without communication
# between the client and server.
keep_alive_interval="30s"
# CA certificate file (optional) # CA certificate file (optional)
# #
# Use this when setting up a secure connection (when server uses ssl://...) # Use this when setting up a secure connection (when server uses ssl://...)

View File

@ -66,6 +66,12 @@
# a random id will be generated by ChirpStack. # a random id will be generated by ChirpStack.
client_id="" client_id=""
# Keep alive interval.
#
# This defines the maximum time that that should pass without communication
# between the client and server.
keep_alive_interval="30s"
# CA certificate file (optional) # CA certificate file (optional)
# #
# Use this when setting up a secure connection (when server uses ssl://...) # Use this when setting up a secure connection (when server uses ssl://...)

View File

@ -66,6 +66,12 @@
# a random id will be generated by ChirpStack. # a random id will be generated by ChirpStack.
client_id="" client_id=""
# Keep alive interval.
#
# This defines the maximum time that that should pass without communication
# between the client and server.
keep_alive_interval="30s"
# CA certificate file (optional) # CA certificate file (optional)
# #
# Use this when setting up a secure connection (when server uses ssl://...) # Use this when setting up a secure connection (when server uses ssl://...)

View File

@ -66,6 +66,12 @@
# a random id will be generated by ChirpStack. # a random id will be generated by ChirpStack.
client_id="" client_id=""
# Keep alive interval.
#
# This defines the maximum time that that should pass without communication
# between the client and server.
keep_alive_interval="30s"
# CA certificate file (optional) # CA certificate file (optional)
# #
# Use this when setting up a secure connection (when server uses ssl://...) # Use this when setting up a secure connection (when server uses ssl://...)

View File

@ -66,6 +66,12 @@
# a random id will be generated by ChirpStack. # a random id will be generated by ChirpStack.
client_id="" client_id=""
# Keep alive interval.
#
# This defines the maximum time that that should pass without communication
# between the client and server.
keep_alive_interval="30s"
# CA certificate file (optional) # CA certificate file (optional)
# #
# Use this when setting up a secure connection (when server uses ssl://...) # Use this when setting up a secure connection (when server uses ssl://...)

View File

@ -66,6 +66,12 @@
# a random id will be generated by ChirpStack. # a random id will be generated by ChirpStack.
client_id="" client_id=""
# Keep alive interval.
#
# This defines the maximum time that that should pass without communication
# between the client and server.
keep_alive_interval="30s"
# CA certificate file (optional) # CA certificate file (optional)
# #
# Use this when setting up a secure connection (when server uses ssl://...) # Use this when setting up a secure connection (when server uses ssl://...)

View File

@ -66,6 +66,12 @@
# a random id will be generated by ChirpStack. # a random id will be generated by ChirpStack.
client_id="" client_id=""
# Keep alive interval.
#
# This defines the maximum time that that should pass without communication
# between the client and server.
keep_alive_interval="30s"
# CA certificate file (optional) # CA certificate file (optional)
# #
# Use this when setting up a secure connection (when server uses ssl://...) # Use this when setting up a secure connection (when server uses ssl://...)

View File

@ -66,6 +66,12 @@
# a random id will be generated by ChirpStack. # a random id will be generated by ChirpStack.
client_id="" client_id=""
# Keep alive interval.
#
# This defines the maximum time that that should pass without communication
# between the client and server.
keep_alive_interval="30s"
# CA certificate file (optional) # CA certificate file (optional)
# #
# Use this when setting up a secure connection (when server uses ssl://...) # Use this when setting up a secure connection (when server uses ssl://...)

View File

@ -66,6 +66,12 @@
# a random id will be generated by ChirpStack. # a random id will be generated by ChirpStack.
client_id="" client_id=""
# Keep alive interval.
#
# This defines the maximum time that that should pass without communication
# between the client and server.
keep_alive_interval="30s"
# CA certificate file (optional) # CA certificate file (optional)
# #
# Use this when setting up a secure connection (when server uses ssl://...) # Use this when setting up a secure connection (when server uses ssl://...)

View File

@ -66,6 +66,12 @@
# a random id will be generated by ChirpStack. # a random id will be generated by ChirpStack.
client_id="" client_id=""
# Keep alive interval.
#
# This defines the maximum time that that should pass without communication
# between the client and server.
keep_alive_interval="30s"
# CA certificate file (optional) # CA certificate file (optional)
# #
# Use this when setting up a secure connection (when server uses ssl://...) # Use this when setting up a secure connection (when server uses ssl://...)

View File

@ -66,6 +66,12 @@
# a random id will be generated by ChirpStack. # a random id will be generated by ChirpStack.
client_id="" client_id=""
# Keep alive interval.
#
# This defines the maximum time that that should pass without communication
# between the client and server.
keep_alive_interval="30s"
# CA certificate file (optional) # CA certificate file (optional)
# #
# Use this when setting up a secure connection (when server uses ssl://...) # Use this when setting up a secure connection (when server uses ssl://...)

View File

@ -66,6 +66,12 @@
# a random id will be generated by ChirpStack. # a random id will be generated by ChirpStack.
client_id="" client_id=""
# Keep alive interval.
#
# This defines the maximum time that that should pass without communication
# between the client and server.
keep_alive_interval="30s"
# CA certificate file (optional) # CA certificate file (optional)
# #
# Use this when setting up a secure connection (when server uses ssl://...) # Use this when setting up a secure connection (when server uses ssl://...)

View File

@ -66,6 +66,12 @@
# a random id will be generated by ChirpStack. # a random id will be generated by ChirpStack.
client_id="" client_id=""
# Keep alive interval.
#
# This defines the maximum time that that should pass without communication
# between the client and server.
keep_alive_interval="30s"
# CA certificate file (optional) # CA certificate file (optional)
# #
# Use this when setting up a secure connection (when server uses ssl://...) # Use this when setting up a secure connection (when server uses ssl://...)

View File

@ -66,6 +66,12 @@
# a random id will be generated by ChirpStack. # a random id will be generated by ChirpStack.
client_id="" client_id=""
# Keep alive interval.
#
# This defines the maximum time that that should pass without communication
# between the client and server.
keep_alive_interval="30s"
# CA certificate file (optional) # CA certificate file (optional)
# #
# Use this when setting up a secure connection (when server uses ssl://...) # Use this when setting up a secure connection (when server uses ssl://...)

View File

@ -66,6 +66,12 @@
# a random id will be generated by ChirpStack. # a random id will be generated by ChirpStack.
client_id="" client_id=""
# Keep alive interval.
#
# This defines the maximum time that that should pass without communication
# between the client and server.
keep_alive_interval="30s"
# CA certificate file (optional) # CA certificate file (optional)
# #
# Use this when setting up a secure connection (when server uses ssl://...) # Use this when setting up a secure connection (when server uses ssl://...)

View File

@ -66,6 +66,12 @@
# a random id will be generated by ChirpStack. # a random id will be generated by ChirpStack.
client_id="" client_id=""
# Keep alive interval.
#
# This defines the maximum time that that should pass without communication
# between the client and server.
keep_alive_interval="30s"
# CA certificate file (optional) # CA certificate file (optional)
# #
# Use this when setting up a secure connection (when server uses ssl://...) # Use this when setting up a secure connection (when server uses ssl://...)

View File

@ -66,6 +66,12 @@
# a random id will be generated by ChirpStack. # a random id will be generated by ChirpStack.
client_id="" client_id=""
# Keep alive interval.
#
# This defines the maximum time that that should pass without communication
# between the client and server.
keep_alive_interval="30s"
# CA certificate file (optional) # CA certificate file (optional)
# #
# Use this when setting up a secure connection (when server uses ssl://...) # Use this when setting up a secure connection (when server uses ssl://...)

View File

@ -66,6 +66,12 @@
# a random id will be generated by ChirpStack. # a random id will be generated by ChirpStack.
client_id="" client_id=""
# Keep alive interval.
#
# This defines the maximum time that that should pass without communication
# between the client and server.
keep_alive_interval="30s"
# CA certificate file (optional) # CA certificate file (optional)
# #
# Use this when setting up a secure connection (when server uses ssl://...) # Use this when setting up a secure connection (when server uses ssl://...)

View File

@ -66,6 +66,12 @@
# a random id will be generated by ChirpStack. # a random id will be generated by ChirpStack.
client_id="" client_id=""
# Keep alive interval.
#
# This defines the maximum time that that should pass without communication
# between the client and server.
keep_alive_interval="30s"
# CA certificate file (optional) # CA certificate file (optional)
# #
# Use this when setting up a secure connection (when server uses ssl://...) # Use this when setting up a secure connection (when server uses ssl://...)

View File

@ -66,6 +66,12 @@
# a random id will be generated by ChirpStack. # a random id will be generated by ChirpStack.
client_id="" client_id=""
# Keep alive interval.
#
# This defines the maximum time that that should pass without communication
# between the client and server.
keep_alive_interval="30s"
# CA certificate file (optional) # CA certificate file (optional)
# #
# Use this when setting up a secure connection (when server uses ssl://...) # Use this when setting up a secure connection (when server uses ssl://...)

View File

@ -66,6 +66,12 @@
# a random id will be generated by ChirpStack. # a random id will be generated by ChirpStack.
client_id="" client_id=""
# Keep alive interval.
#
# This defines the maximum time that that should pass without communication
# between the client and server.
keep_alive_interval="30s"
# CA certificate file (optional) # CA certificate file (optional)
# #
# Use this when setting up a secure connection (when server uses ssl://...) # Use this when setting up a secure connection (when server uses ssl://...)

View File

@ -66,6 +66,12 @@
# a random id will be generated by ChirpStack. # a random id will be generated by ChirpStack.
client_id="" client_id=""
# Keep alive interval.
#
# This defines the maximum time that that should pass without communication
# between the client and server.
keep_alive_interval="30s"
# CA certificate file (optional) # CA certificate file (optional)
# #
# Use this when setting up a secure connection (when server uses ssl://...) # Use this when setting up a secure connection (when server uses ssl://...)

View File

@ -66,6 +66,12 @@
# a random id will be generated by ChirpStack. # a random id will be generated by ChirpStack.
client_id="" client_id=""
# Keep alive interval.
#
# This defines the maximum time that that should pass without communication
# between the client and server.
keep_alive_interval="30s"
# CA certificate file (optional) # CA certificate file (optional)
# #
# Use this when setting up a secure connection (when server uses ssl://...) # Use this when setting up a secure connection (when server uses ssl://...)

View File

@ -66,6 +66,12 @@
# a random id will be generated by ChirpStack. # a random id will be generated by ChirpStack.
client_id="" client_id=""
# Keep alive interval.
#
# This defines the maximum time that that should pass without communication
# between the client and server.
keep_alive_interval="30s"
# CA certificate file (optional) # CA certificate file (optional)
# #
# Use this when setting up a secure connection (when server uses ssl://...) # Use this when setting up a secure connection (when server uses ssl://...)

View File

@ -66,6 +66,12 @@
# a random id will be generated by ChirpStack. # a random id will be generated by ChirpStack.
client_id="" client_id=""
# Keep alive interval.
#
# This defines the maximum time that that should pass without communication
# between the client and server.
keep_alive_interval="30s"
# CA certificate file (optional) # CA certificate file (optional)
# #
# Use this when setting up a secure connection (when server uses ssl://...) # Use this when setting up a secure connection (when server uses ssl://...)

View File

@ -351,6 +351,12 @@ pub fn run() {
# a random id will be generated by ChirpStack. # a random id will be generated by ChirpStack.
client_id="{{ integration.mqtt.client_id }}" client_id="{{ integration.mqtt.client_id }}"
# Keep alive interval.
#
# This defines the maximum time that that should pass without communication
# between the client and server.
keep_alive_interval="{{ integration.mqtt.keep_alive_interval }}"
# CA certificate file (optional) # CA certificate file (optional)
# #
# Use this when setting up a secure connection (when server uses ssl://...) # Use this when setting up a secure connection (when server uses ssl://...)

View File

@ -270,6 +270,8 @@ pub struct MqttIntegration {
pub ca_cert: String, pub ca_cert: String,
pub tls_cert: String, pub tls_cert: String,
pub tls_key: String, pub tls_key: String,
#[serde(with = "humantime_serde")]
pub keep_alive_interval: Duration,
} }
impl Default for MqttIntegration { impl Default for MqttIntegration {
@ -289,6 +291,7 @@ impl Default for MqttIntegration {
ca_cert: "".into(), ca_cert: "".into(),
tls_cert: "".into(), tls_cert: "".into(),
tls_key: "".into(), tls_key: "".into(),
keep_alive_interval: Duration::from_secs(30),
} }
} }
} }
@ -537,8 +540,6 @@ impl Default for Region {
event_topic: "eu868/gateway/+/event/+".into(), event_topic: "eu868/gateway/+/event/+".into(),
command_topic: "eu868/gateway/{{ gateway_id }}/command/{{ command }}" command_topic: "eu868/gateway/{{ gateway_id }}/command/{{ command }}"
.into(), .into(),
server: "tcp://127.0.0.1:1883".into(),
clean_session: false,
..Default::default() ..Default::default()
}, },
}, },
@ -612,7 +613,7 @@ pub struct GatewayBackend {
pub mqtt: GatewayBackendMqtt, pub mqtt: GatewayBackendMqtt,
} }
#[derive(Default, Serialize, Deserialize, Clone)] #[derive(Serialize, Deserialize, Clone)]
#[serde(default)] #[serde(default)]
pub struct GatewayBackendMqtt { pub struct GatewayBackendMqtt {
pub event_topic: String, pub event_topic: String,
@ -626,6 +627,27 @@ pub struct GatewayBackendMqtt {
pub ca_cert: String, pub ca_cert: String,
pub tls_cert: String, pub tls_cert: String,
pub tls_key: String, pub tls_key: String,
#[serde(with = "humantime_serde")]
pub keep_alive_interval: Duration,
}
impl Default for GatewayBackendMqtt {
fn default() -> Self {
GatewayBackendMqtt {
event_topic: "".into(),
command_topic: "".into(),
server: "tcp://127.0.0.1:1883/".into(),
username: "".into(),
password: "".into(),
qos: 0,
clean_session: false,
client_id: "".into(),
ca_cert: "".into(),
tls_cert: "".into(),
tls_key: "".into(),
keep_alive_interval: Duration::from_secs(30),
}
}
} }
#[derive(Serialize, Deserialize, Clone, Hash)] #[derive(Serialize, Deserialize, Clone, Hash)]

View File

@ -143,6 +143,7 @@ impl<'a> MqttBackend<'a> {
let mut conn_opts_b = mqtt::ConnectOptionsBuilder::new(); let mut conn_opts_b = mqtt::ConnectOptionsBuilder::new();
conn_opts_b.automatic_reconnect(Duration::from_secs(1), Duration::from_secs(30)); conn_opts_b.automatic_reconnect(Duration::from_secs(1), Duration::from_secs(30));
conn_opts_b.clean_session(conf.clean_session); conn_opts_b.clean_session(conf.clean_session);
conn_opts_b.keep_alive_interval(conf.keep_alive_interval);
conn_opts_b.user_name(&conf.username); conn_opts_b.user_name(&conf.username);
conn_opts_b.password(&conf.password); conn_opts_b.password(&conf.password);
if !conf.ca_cert.is_empty() || !conf.tls_cert.is_empty() || !conf.tls_key.is_empty() { if !conf.ca_cert.is_empty() || !conf.tls_cert.is_empty() || !conf.tls_key.is_empty() {

View File

@ -99,6 +99,7 @@ impl<'a> Integration<'a> {
let mut conn_opts_b = mqtt::ConnectOptionsBuilder::new(); let mut conn_opts_b = mqtt::ConnectOptionsBuilder::new();
conn_opts_b.automatic_reconnect(Duration::from_secs(1), Duration::from_secs(30)); conn_opts_b.automatic_reconnect(Duration::from_secs(1), Duration::from_secs(30));
conn_opts_b.clean_session(conf.clean_session); conn_opts_b.clean_session(conf.clean_session);
conn_opts_b.keep_alive_interval(conf.keep_alive_interval);
conn_opts_b.user_name(&conf.username); conn_opts_b.user_name(&conf.username);
conn_opts_b.password(&conf.password); conn_opts_b.password(&conf.password);
if !conf.ca_cert.is_empty() || !conf.tls_cert.is_empty() || !conf.tls_key.is_empty() { if !conf.ca_cert.is_empty() || !conf.tls_cert.is_empty() || !conf.tls_key.is_empty() {