Description
Helper class to help safely use MQTTClient’s BeginPacketBuffer
-EndPacketBuffer
pairs in a using. With BeginPacketBuffer
and EndPacketBuffer
Best MQTT can send less network packets to the broker.
Examples
using (new PacketBufferHelper(client))
{
client.CreateUnsubscribePacketBuilder("/#")
.BeginUnsubscribe();
client.CreateBulkSubscriptionBuilder()
.WithTopic(new SubscribeTopicBuilder("$SYS/#")
.WithMaximumQoS(QoSLevels.ExactlyOnceDelivery)
.WithMessageCallback(OnSysMessages)
.WithAcknowledgementCallback(OnSysMessagesSubscribeAck))
.WithTopic(new SubscribeTopicBuilder("/test/msgs")
.WithMaximumQoS(QoSLevels.ExactlyOnceDelivery)
.WithMessageCallback(OnTestMessages)
.WithAcknowledgementCallback(OnTestMessagesSubscribeAck))
.BeginSubscribe();
}
The same behavior using BeginPacketBuffer
-EndPacketBuffer
would be the following:
client.BeginPacketBuffer();
try
{
client.CreateUnsubscribePacketBuilder("/#")
.BeginUnsubscribe();
client.CreateBulkSubscriptionBuilder()
.WithTopic(new SubscribeTopicBuilder("$SYS/#")
.WithMaximumQoS(QoSLevels.ExactlyOnceDelivery)
.WithMessageCallback(OnSysMessages)
.WithAcknowledgementCallback(OnSysMessagesSubscribeAck))
.WithTopic(new SubscribeTopicBuilder("/test/msgs")
.WithMaximumQoS(QoSLevels.ExactlyOnceDelivery)
.WithMessageCallback(OnTestMessages)
.WithAcknowledgementCallback(OnTestMessagesSubscribeAck))
.BeginSubscribe();
}
finally
{
client.EndPacketBuffer();
}