-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Upgrading guide
Christian edited this page Jan 30, 2022
·
30 revisions
- A lot of namespaces have changed in the server component. Basically all classes are still there but have to be imported using new namespaces.
- The entire library now uses async events instead of handles implemented by interfaces. So every interface implementation like application message received handler in the client must be ported to an async event handler. The former context information is still available as regular event argument classes. When an event is not async it should return Task.CompletedTask.
- The server and client classes no longer support interface (IMqttClient etc.). The should be encapsulated in custom clients.
- A lot of overloads and extension methods have been removed to keep the public API clean and small. Thus previously used extension methods etc. must be created again in user code.
- Due to security reasons the default (unencrypted) endpoint is no longer enabled by default. It is still present and can be activated via existing APIs.
- The Server and the Clients no longer share common interfaces like IApplicationMessagePublisher. They now have unique implementations offering the best API for each purpose.
-
MQTTnet.Adapter.MqttChannelAdapter
constructor has additional argumentIMqttPacketInspector
which is avalable as prroperty inMQTTnet.Client.Options.IMqttClientOptions
.
- Rename namespace
MQTTnet.AspNetCore
toMQTTnet.AspNetCore.Extensions
.
- Argument
logger
removed fromIMqttChannelAdapter MQTTnet.Adapter.CreateClientAdapter(IMqttClientOptions options, IMqttNetLogger logger)
. Create a constructor in your AdapterFactory and pass there the logger. - Pass the root logger to
MQTTnet.Adapter.MqttChannelAdapter
. For other use cases where you previously created anCreateChildLogger
create aCreateScopedLogger
.
- Replace
MQTTnet.Diagnostics.IMqttNetChildLogger
withMQTTnet.Diagnostics.IMqttNetLogger
. - Replace
MQTTnet.AspNetCore.ApplicationBuilderExtensions.SelectSubProtocol(requestedSubProtocolValues)
withMQTTnet.AspNetCore.MqttSubProtocolSelector.SelectSubProtocol(requestedSubProtocolValues)
. - Class
MQTTnet.AspNetCore.ApplicationBuilderExtensions
is deprecated and will be removed in a future version.
- Nothing special at the moment.
- There is a new
Dictionary<object, object>
calledSessionItems
. It allows to store custom data in the session and is available in all interceptors. For more examples, check https://github.com/chkr1011/MQTTnet/wiki/Server#storing-data-in-the-session.
-
MqttConnectReturnCode
is now deprecated, useMqttConnectReasonCode
instead. -
ConnectAsync
has now a CancellationToken and can be used like this:await mqttClient.ConnectAsync(options, CancellationToken.None));
-
MqttProtocolVersion
is now in theMQTTnet.Formatter
namespace. -
MqttFixedHeader
,MqttPacketBodyReader
,MqttPacketReader
,MqttPacketWriter
andMqttProtocolVersion
are now in theMQTTnet.Formatter
namespace. -
IMqttPacketSerializer
andMqttPacketSerializer
do not exist anymore.
- Updated async handlers:
private void Something()
{
mqttClient.ApplicationMessageReceivedHandler = new MqttApplicationMessageReceivedHandlerDelegate(OnAppMessage);
mqttClient.ConnectedHandler = new MqttClientConnectedHandlerDelegate(OnConnected);
mqttClient.DisconnectedHandler = new MqttClientDisconnectedHandlerDelegate(OnDisconnected);
mqttClient.ConnectingFailedHandler = new ConnectingFailedHandlerDelegate(OnConnectingFailed);
}
private async void OnAppMessage(MqttApplicationMessageReceivedEventArgs e)
{
}
private async void OnConnected(MqttClientConnectedEventArgs e)
{
}
private async void OnDisconnected(MqttClientDisconnectedEventArgs e)
{
}
private async void OnConnectingFailed(ManagedProcessFailedEventArgs e)
{
}
- Updated async handlers:
private void Something()
{
mqttClient.ApplicationMessageReceivedHandler = new MqttApplicationMessageReceivedHandlerDelegate(OnAppMessage);
mqttClient.ConnectedHandler = new MqttClientConnectedHandlerDelegate(OnConnected);
mqttClient.DisconnectedHandler = new MqttClientDisconnectedHandlerDelegate(OnDisconnected);
}
private async void OnAppMessage(MqttApplicationMessageReceivedEventArgs e)
{
}
private async void OnConnected(MqttClientConnectedEventArgs e)
{
}
private async void OnDisconnected(MqttClientDisconnectedEventArgs e)
{
}
- Checkout the issue under https://github.com/chkr1011/MQTTnet/issues/781 or open new issues if you are unsure.