Skip to content

Commit

Permalink
fix update reported with ack
Browse files Browse the repository at this point in the history
  • Loading branch information
ridomin committed Oct 1, 2022
1 parent 58c9b0a commit 62da247
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public TwinRequestResponseBinder(IMqttClient connection)
{
Trace.TraceWarning($"GetTwinBinder: RID {rid} not found pending requests");
}
}
if (topic.StartsWith("$iothub/twin/res/204"))
}
else if (topic.StartsWith("$iothub/twin/res/204"))
{
string msg = Encoding.UTF8.GetString(m.ApplicationMessage.Payload ?? new byte[0]);
(int rid, int version) = TopicParser.ParseTopic(topic);
Expand All @@ -52,6 +52,11 @@ public TwinRequestResponseBinder(IMqttClient connection)
Trace.TraceWarning($"UpdateTwinBinder: RID {rid} not found pending requests");
}
}
else if (topic.StartsWith("$iothub/twin/res"))
{
Trace.TraceWarning("topic: " + m.ApplicationMessage.Topic);
Trace.TraceWarning("msg : " + Encoding.UTF8.GetString(m.ApplicationMessage.Payload!));
}
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public WritableProperty(IMqttClient c, string name)
_name = name;
_connection = c;
TopicTemplate = "$iothub/twin/PATCH/properties/desired/#";
ResponseTopic = "$iothub/twin/PATCH/properties/reported/?$rid={rid}&$version={version}";
ResponseTopic = "$iothub/twin/PATCH/properties/reported/?$rid={rid}";
UnwrapRequest = true;
WrapResponse = true;
PreProcessMessage = tp =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public CloudToDeviceBinder(IMqttClient connection, string name, IMessageSerializ
.WithPayload(responseBytes)
.WithQualityOfServiceLevel(MqttQualityOfServiceLevel.AtLeastOnce)
.WithRetainFlag(RetainResponse)
.WithPayloadFormatIndicator(serializer is UTF8JsonSerializer ? MqttPayloadFormatIndicator.CharacterData : MqttPayloadFormatIndicator.Unspecified)
//.WithPayloadFormatIndicator(serializer is UTF8JsonSerializer ? MqttPayloadFormatIndicator.CharacterData : MqttPayloadFormatIndicator.Unspecified)
.Build());
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void DesiredPropGetsTriggeredAndIsReportedBackWithAck()
};

mqttClient.SimulateNewMessage("$iothub/twin/PATCH/properties/desired/?$rid=1&$version=3", Stringify(desiredMsg));
Assert.StartsWith($"$iothub/twin/PATCH/properties/reported/?$rid=1&$version=3", mqttClient.topicRecceived);
Assert.StartsWith($"$iothub/twin/PATCH/properties/reported/?$rid=1", mqttClient.topicRecceived);

var expected = Stringify(new
{
Expand Down Expand Up @@ -75,7 +75,7 @@ public void ReceiveWPWithVersion()
Assert.True(propReceived);
Assert.Equal(4, wp.Version);
Assert.Equal("string value", wp.Value);
Assert.Equal($"$iothub/twin/PATCH/properties/reported/?$rid=1&$version=3", mockMqtt.topicRecceived);
Assert.Equal($"$iothub/twin/PATCH/properties/reported/?$rid=1", mockMqtt.topicRecceived);
Assert.Equal("{\"aStringProp\":{\"av\":4,\"ac\":200,\"value\":\"string value\"}}", mockMqtt.payloadReceived);

propReceived = false;
Expand All @@ -84,7 +84,7 @@ public void ReceiveWPWithVersion()
Assert.True(propReceived);
Assert.Equal(5, wp.Version);
Assert.Equal("second string value", wp.Value);
Assert.Equal($"$iothub/twin/PATCH/properties/reported/?$rid=1&$version=4", mockMqtt.topicRecceived);
Assert.Equal($"$iothub/twin/PATCH/properties/reported/?$rid=1", mockMqtt.topicRecceived);
Assert.Equal("{\"aStringProp\":{\"av\":5,\"ac\":200,\"value\":\"second string value\"}}", mockMqtt.payloadReceived);


Expand Down

0 comments on commit 62da247

Please sign in to comment.