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

fix: built-in MQTT bridge handling of QoS 0 messages published to the cloud topic #3028

Merged
merged 3 commits into from
Jul 31, 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
18 changes: 17 additions & 1 deletion crates/extensions/tedge_mqtt_bridge/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,23 @@ async fn half_bridge(

// Keep track of packet IDs so we can acknowledge messages
Event::Outgoing(Outgoing::Publish(pkid)) => {
if let hash_map::Entry::Vacant(e) = forward_pkid_to_received_msg.entry(pkid) {
if pkid == 0 {
// Messages with pkid 0 (meaning QoS=0) should not be added to the hashmap
// as multiple messages with the pkid=0 can be received
match companion_bridge_half.recv().await {
// A message was forwarded by the other bridge half, note the packet id
Some(Some((topic, msg))) => {
loop_breaker.forward_on_topic(topic, &msg);
}

// A healthcheck message was published, ignore this packet id
Some(None) => {}

// The other bridge half has disconnected, break the loop and shut down the bridge
None => break,
}
} else if let hash_map::Entry::Vacant(e) = forward_pkid_to_received_msg.entry(pkid)
{
match companion_bridge_half.recv().await {
// A message was forwarded by the other bridge half, note the packet id
Some(Some((topic, msg))) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
*** Settings ***
Resource ../../../resources/common.resource
Library Cumulocity
Library ThinEdgeIO

Test Setup Custom Setup
Test Teardown Get Logs

*** Test Cases ***

Connection test
[Documentation] Repeatedly test the cloud connection
FOR ${attempt} IN RANGE 0 10 1
${output}= Execute Command tedge connect c8y --test timeout=10
Should Not Contain ${output} connection check failed
END


Support publishing QoS 0 messages to c8y topic #2960
[Documentation] Verify the publishing of multiple QoS 0 message directly to the cloud connection
... Note 1: Since QoS 0 aren't guarenteed to be delivered, use a non-strict assertion on the exact event count in the cloud.
... During testing the test would reliably fail if the expected count is less than 10 messages.
... Note 2: The bridge will automatically change the QoS from 0 when translating messages from te/# to c8y/#,
... we can't use the te/# topics in the test.
FOR ${attempt} IN RANGE 0 20 1
Execute Command tedge mqtt pub -q 0 c8y/s/us '400,test_q0,Test event with qos 0 attempt ${attempt}' timeout=10
END
Cumulocity.Device Should Have Event/s expected_text=Test event with qos 0.* type=test_q0 minimum=10


*** Keywords ***

Custom Setup
${DEVICE_SN}= Setup
Set Suite Variable ${DEVICE_SN}
Execute Command tedge config set mqtt.bridge.built_in true
Execute Command tedge reconnect c8y