Skip to content

Commit

Permalink
feat(rumqttd): unsubscribe method in local link (#894)
Browse files Browse the repository at this point in the history
  • Loading branch information
Devdutt Shenoi authored Jul 31, 2024
1 parent 6f78e5f commit 11d2e97
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions rumqttd/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added
- Assign random identifier to clients connecting with empty client id.
- `Unsubscribe` with `local::LinkTx`.

### Changed
- Public re-export `Strategy` for shared subscriptions
Expand Down
23 changes: 23 additions & 0 deletions rumqttd/src/link/local.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::protocol::{
Filter, LastWill, LastWillProperties, Packet, Publish, QoS, RetainForwardRule, Subscribe,
Unsubscribe,
};
use crate::router::Ack;
use crate::router::{
Expand Down Expand Up @@ -281,6 +282,28 @@ impl LinkTx {
Ok(len)
}

/// Sends a MQTT Unsubscribe to the eventloop
pub fn unsubscribe<S: Into<String>>(&mut self, filter: S) -> Result<usize, LinkError> {
let unsubscribe = Unsubscribe {
pkid: 0,
filters: vec![filter.into()],
};

let len = self.push(Packet::Unsubscribe(unsubscribe, None))?;
Ok(len)
}

/// Sends a MQTT Unsubscribe to the eventloop
pub fn try_unsubscribe<S: Into<String>>(&mut self, filter: S) -> Result<usize, LinkError> {
let unsubscribe = Unsubscribe {
pkid: 0,
filters: vec![filter.into()],
};

let len = self.try_push(Packet::Unsubscribe(unsubscribe, None))?;
Ok(len)
}

/// Request to get device shadow
pub fn shadow<S: Into<String>>(&mut self, filter: S) -> Result<(), LinkError> {
let message = Event::Shadow(ShadowRequest {
Expand Down

0 comments on commit 11d2e97

Please sign in to comment.