Skip to content

Commit

Permalink
Merge pull request #3028 from reubenmiller/fix-builtin-bridge-qos-0
Browse files Browse the repository at this point in the history
fix: built-in MQTT bridge handling of QoS 0 messages published to the cloud topic
  • Loading branch information
reubenmiller authored Jul 31, 2024
2 parents 359a4b0 + bf9ed50 commit 52b39ff
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
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

0 comments on commit 52b39ff

Please sign in to comment.