Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No valid replacement for the obsolete MqttClientOptionsBuilder.WithConnectionUri #1979

Closed
mrudat opened this issue Apr 26, 2024 · 1 comment · Fixed by #1998
Closed

No valid replacement for the obsolete MqttClientOptionsBuilder.WithConnectionUri #1979

mrudat opened this issue Apr 26, 2024 · 1 comment · Fixed by #1998
Labels
bug Something isn't working

Comments

@mrudat
Copy link

mrudat commented Apr 26, 2024

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()
@mrudat mrudat added the bug Something isn't working label Apr 26, 2024
@chkr1011
Copy link
Collaborator

You are right. I will remove the obsolete attribute from both methods.

@chkr1011 chkr1011 linked a pull request May 17, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants