Skip to content

No valid replacement for the obsolete MqttClientOptionsBuilder.WithConnectionUri #1979

@mrudat

Description

@mrudat

Describe the bug

There is no valid replacement for MqttClientOptionBuilder.WithConnectionUri that will accept the same range of URIs as the original method.

Which component is your bug related to?

  • Client
  • ManagedClient

To Reproduce

  1. Using this version of MQTTnet '4.3.3.952'.

Expected behaviour

Something that accepts an arbitrary supported URI and produces a valid MqttClientOptions for connecting to the MQTT server described by the URI.

Code example

WithConnectionUri is marked as Obsolete:

var mqttClientOptions = mqttFactory.CreateClientOptionsBuilder()
    .WithConnectionUri(configuration.GetUri())
    .Build()

It suggests using WithWebSocketServer, which assumes you know that the given URI uses WebSockets and will presumably fail if it is not a WebSockets URI:

var mqttClientOptions = mqttFactory.CreateClientOptionsBuilder()
    // Note: you must explicitly declare the type. Otherwise, it uses _another_ deprecated method of the same name.
    .WithWebSocketServer((MqttClientWebSocketOptionsBuilder opt) => {
        opt.WithUri(image.GetUri());
    })
    .Build()

Alternatively, it suggests using WtihTcpServer, which can't parse any URIs:

var mqttClientOptions = mqttFactory.CreateClientOptionsBuilder()
    .WithTcpServer((MqttClientWebSocketOptionsBuilder opt) => {
        opt.WithUri(image.GetUri()); // <-- compile error, no such method.
    })
    .Build()

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions