Skip to content

Upgrading guide

HansM edited this page Jun 8, 2022 · 30 revisions

From 3.x to 4.0.0:

  • 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. This is a preparation in order to move the server components into a dedicated nuget package.
  • Several APIs were removed from the builder to keep the API small and clean. If a used API is gone there should be another suitable overload.

Required Code Changes:

  • TopicFilter:

    MqttTopicFilterComparer.IsMatch(x, y)

    to

    MqttTopicFilterComparer.Compare(x, y) == MqttTopicFilterCompareResult.IsMatch)
  • ClientUnsubscribedTopicHandler:

    server.ClientUnsubscribedTopicHandler = new MqttServerClientUnsubscribedTopicHandlerDelegate(e => { ... });

    to

    server.ClientUnsubscribedTopicAsync += async e => { ... };
  • ApplicationMessageReceivedHandler:

    server.ApplicationMessageReceivedHandler = new MqttApplicationMessageReceivedHandlerDelegate(e => { ... });

    to

    server.InterceptingPublishAsync += async e => { ... };
  • General server startup:

    var options = new MqttServerOptionsBuilder();
    var mqttFactory = new MqttFactory();
    var server = mqttFactory.CreateMqttServer(_serverLogger);
    await server.StartAsync(options.WithDefaultEndpointPort(port).Build());

    to

    var options = new MqttServerOptionsBuilder();
    var mqttFactory = new MqttFactory();
    var server = mqttFactory.CreateMqttServer(options.WithDefaultEndpointPort(port).Build(), _serverLogger);
    await server.StartAsync();

From 3.0.13 to 3.0.14:

  • MQTTnet.Adapter.MqttChannelAdapter constructor has additional argument IMqttPacketInspector which is avalable as prroperty in MQTTnet.Client.Options.IMqttClientOptions.

From 3.0.11 to 3.0.12 or 3.0.13:

  • Rename namespace MQTTnet.AspNetCore to MQTTnet.AspNetCore.Extensions.

From 3.0.9 to 3.0.10 or 3.0.11:

  • Argument logger removed from IMqttChannelAdapter 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 an CreateChildLogger create a CreateScopedLogger.

From 3.0.8 to 3.0.9:

  • Replace MQTTnet.Diagnostics.IMqttNetChildLoggerwith MQTTnet.Diagnostics.IMqttNetLogger.
  • Replace MQTTnet.AspNetCore.ApplicationBuilderExtensions.SelectSubProtocol(requestedSubProtocolValues) with MQTTnet.AspNetCore.MqttSubProtocolSelector.SelectSubProtocol(requestedSubProtocolValues).
  • Class MQTTnet.AspNetCore.ApplicationBuilderExtensions is deprecated and will be removed in a future version.

From 3.0.6 to 3.0.7 or 3.0.8:

  • Nothing special at the moment.

From 3.0.5 to 3.0.6:

From 3.0.3 to 3.0.5:

  • MqttConnectReturnCode is now deprecated, use MqttConnectReasonCode instead.
  • ConnectAsync has now a CancellationToken and can be used like this: await mqttClient.ConnectAsync(options, CancellationToken.None));

From 2.8.5 to 3.0.0:

General:

  • MqttProtocolVersion is now in the MQTTnet.Formatter namespace.
  • MqttFixedHeader, MqttPacketBodyReader, MqttPacketReader, MqttPacketWriter and MqttProtocolVersion are now in the MQTTnet.Formatter namespace.
  • IMqttPacketSerializer and MqttPacketSerializer do not exist anymore.

ManagedClient:

  • 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)
{
}

Client:

  • 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)
{
}

From 2.7.5 to 3.x.x:

General:

Clone this wiki locally