TLS 1.3 over MQTT broker and client

I am using rumqttd as a broker, I keep receiving errors when I try implementing TLS 1.3 over my client code which is
use tokio::{task, time};

use rumqttc::{self, AsyncClient, MqttOptions, QoS};
use std::error::Error;
use std::time::Duration;

#[tokio::main(worker_threads = 1)]
async fn main() → Result<(), Box> {
// color_backtrace::install();

let mut broker = "";
if env!("HOME") == "/root" {
  broker = "mqtt-broker";

let mut mqttoptions = MqttOptions::new("test-1", broker, 1883);

let (client, mut eventloop) = AsyncClient::new(mqttoptions, 19);
task::spawn(async move {

loop {
    let event = eventloop.poll().await;
    match &event {
        Ok(v) => {
            println!("Event = {v:?}");
        Err(e) => {
            println!("Error = {e:?}");
            return Ok(());


async fn requests(client: AsyncClient) {
.subscribe(“hello/world”, QoS::AtMostOnce)

for i in 1..=19 {
        .publish("hello/world", QoS::AtMostOnce, false, vec![1; i])




Can someone please help me to modify this code and provide me the cargo toml?

This is where I came so far but I am receiving 10 errors for this version

use std::fs;
use std::io::BufReader;
use std::net::TcpStream;
use std::path::Path;

use futures_util::future::{FutureExt, TryFutureExt};
use tokio::io::{AsyncBufReadExt, AsyncWriteExt, BufReader as AsyncBufReader};
use tokio::net::TcpStream as AsyncTcpStream;
use tokio_rustls::client::TlsStream;
use tokio_rustls::rustls::internal::pemfile::{certs, pkcs8_private_keys};
use tokio_rustls::rustls::{ClientConfig, NoClientAuth, ServerCertVerified, TLSError};
use tokio_rustls::TlsConnector;
use mqtt3::RequestError;
use mqtt3::{MqttRead, MqttWrite, QoS};

async fn main() → Result<(), Box> {
// Load the certificates and private key
let certfile = &mut BufReader::new(fs::File::open(“certs/cert.pem”)?);
let keyfile = &mut BufReader::new(fs::File::open(“certs/key.pem”)?);
let cert_chain = certs(certfile).unwrap();
let mut keys = pkcs8_private_keys(keyfile).unwrap();
let key = keys.remove(0);

// Create the TLS configuration
let mut client_config = ClientConfig::new();
    .set_single_client_cert(cert_chain, key)
    .map_err(|e| RequestError::SslError(e.to_string()))?;

// Create the TLS connector
let tls_connector = TlsConnector::from(Arc::new(client_config));

// Connect to the broker
let mut mqttoptions = mqtt3::MqttOptions::new("test-1", "localhost", 8883);

// Create a new AsyncClient with the TLS connector
let stream = AsyncTcpStream::connect("localhost:8883").await?;
let stream = tls_connector.connect("localhost", stream).await?;

let mut client = mqtt3::AsyncClient::new(stream, 10);
let mut eventloop = client.eventloop();

// Connect to the broker
let (ack, _) = eventloop.connect(mqttoptions).await?;
println!("Connected: {:?}", ack);

// Subscribe to a topic
    .subscribe("test", QoS::AtMostOnce)

// Publish a message to the topic
    .publish("test", QoS::AtMostOnce, false, "Hello, world!".to_string())

// Read messages from the topic
let mut stream =;
while let Some(msg) = stream.try_next().await? {
    println!("Received: {:?}", msg);



Hello @sinem ,

Thank you for the outreach and interested in HiveMQ!

One detail I wanted to confirm first is if TLS version 1.3 has been specified as the protocol version on your broker. This will ensure that TLS 1.3 is supported by the broker, as well. Some more information, including a code example using the HiveMQ Client, is available in this thread.

Aaron from HiveMQ Team

Dear AaronTLFranz,
By any chance is there a client code written in RUST language?

Hello @sinem ,

There are client libraries that exist for RUST, though they are not maintained by HiveMQ. For example, the Eclipse Paho Rust Client Library can be found here.

Aaron from HiveMQ Team