eclipse / paho.mqtt.rust

paho.mqtt.rust
Other
511 stars 102 forks source link

Bad protocol error in examples #184

Closed ACenTe25 closed 1 year ago

ACenTe25 commented 1 year ago

I was following the example in examples/sync_consume.rs and couldn't create a Client due to a Bad protocol error.

According to the documentation in paho_mqtt::errors::BadProtocol:

Protocol prefix in serverURI must be “tcp://”, “ssl://”, “ws://”, or “wss://” The TLS enabled prefixes (ssl, wss) are only valid when using the AAL/TLS version of the library.

However, the aforementioned example has (lines 65 - 74):

let host = env::args()
    .nth(1)
    .unwrap_or_else(|| "mqtt://localhost:1883".to_string());

// Create the client. Use an ID for a persistent session.
// A real system should try harder to use a unique ID.
let create_opts = mqtt::CreateOptionsBuilder::new()
    .server_uri(host)
    .client_id("rust_sync_consumer")
    .finalize();

Which causes the error because the prefix in the example is mqtt:// (line 67) which is invalid.

Am I missing some feature or some important note in order to make the mqtt:// prefix work, or is the example wrong?

fpagliughi commented 1 year ago

Are you testing out an unreleased version from GitHub? (Or using an example from GitHub with a released version from crates.io)?

Either way... The mqtt:// and mqtts://prefixes have become de-facto standard in the industry, but the underlying Paho C library did not support them using tcp:// and ssl:// instead. I recently added the "standard" prefixes to the C library, which got released in Paho C v1.3.11.

This Rust lib has yet to be released with that support, though the GitHub repo has been updated in preparation for it coming soon. The new library should be out in a week or two.

ACenTe25 commented 1 year ago

Oh, I see... I was using the example from GitHub with a released version from crates.io. thanks for clarifying!