Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add MQTT v5 connection session_expiry_interval support #854

Merged
merged 5 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions rumqttc/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* `size()` method on `Packet` calculates size once serialized.
* `read()` and `write()` methods on `Packet`.
* `ConnectionAborted` variant on `StateError` type to denote abrupt end to a connection
* `set_session_expiry_interval` and `session_expiry_interval` methods on `MqttOptions`.

### Changed

Expand Down
1 change: 1 addition & 0 deletions rumqttc/examples/async_manual_acks_v5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ fn create_conn() -> (AsyncClient, EventLoop) {
let mut mqttoptions = MqttOptions::new("test-1", "localhost", 1884);
mqttoptions
.set_keep_alive(Duration::from_secs(5))
.set_session_expiry_interval(u32::MAX.into())
swanandx marked this conversation as resolved.
Show resolved Hide resolved
.set_manual_acks(true)
.set_clean_start(false);

Expand Down
5 changes: 5 additions & 0 deletions rumqttc/src/v5/eventloop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,11 @@ async fn mqtt_connect(
options.keep_alive = Duration::from_secs(keep_alive as u64);
}
network.set_max_outgoing_size(props.max_packet_size);

// Override local session_expiry_interval value if set by server.
if props.session_expiry_interval.is_some() {
options.set_session_expiry_interval(props.session_expiry_interval);
}
}
Ok(Packet::ConnAck(connack))
}
Expand Down
21 changes: 21 additions & 0 deletions rumqttc/src/v5/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,27 @@ impl MqttOptions {
self.connect_properties.clone()
}

/// set session expiry interval on connection properties
pub fn set_session_expiry_interval(&mut self, interval: Option<u32>) -> &mut Self {
if let Some(conn_props) = &mut self.connect_properties {
conn_props.session_expiry_interval = interval;
self
} else {
let mut conn_props = ConnectProperties::new();
conn_props.session_expiry_interval = interval;
self.set_connect_properties(conn_props)
}
}

/// get session expiry interval on connection properties
pub fn session_expiry_interval(&self) -> Option<u32> {
if let Some(conn_props) = &self.connect_properties {
conn_props.session_expiry_interval
} else {
None
}
}

/// set receive maximum on connection properties
pub fn set_receive_maximum(&mut self, recv_max: Option<u16>) -> &mut Self {
if let Some(conn_props) = &mut self.connect_properties {
Expand Down