Skip to content

Tips and Tricks

Ramon Smits edited this page Jun 5, 2019 · 15 revisions

Logging

It is recommended to disable logging (Global logger or custom logger) which running in a live environment because it adds a huge overhead to message processing. It should be avoided to attach to the global MQTTnet logger at all because an already attached method (which may not process the entry further on) leads to generation of log messages internally.

Prefer builders

MQTTnet comes with some builders like the MqttClientOptionsBuilder or MqttApplicationMessageBuilder which are supporting a fluent API. Also these builders are used to achieve version compatibility. It is supported to change the MqttClientOptions class directly but this file may have breaking changes across versions of MQTTnet. The builders instead will usually provide backward compatibility (when possible).

MQTT best practices

This project only covers the implementation of a basic MQTT library. For best practices, general recommendation ans specifications please visit https://www.hivemq.com/mqtt/.

Prevent processing event published by publisher

The broker does not distinguish. Every message is treated the same. But you can skip events the publisher also publishes to itself by checking the ClientId. If this is set to null the message was sent by the server directly.

Clone this wiki locally