Skip to content
Proyectos

Acerca de

Framework de cliente y servidor MQTT para los protocolos v5 y v3.1.1.

Sistemas e infraestructura

Cómo se miden estas cifras

What you can do

  • MQTT v3.1.1 and v5 protocols, a single server can serve both
  • Client and server
  • Streaming publish payloads, large messages are processed in chunks
  • Flow control: receive maximum, in-flight size limits and read pause

Crecimiento de estrellas medido

in 24h
0
in 7 days
0
in 15 days
0
in 1 month
Recopilando historial

Cambios netos en períodos que se solapan, no totales diarios. Los datos no disponibles se dejan en blanco. Las estrellas indican interés, no calidad.

README.md

Original

MQTT Client/Server framework

build status codecov crates.io Documentation

MQTT Client/Server framework for ntex with support of v5 and v3.1.1 protocols.

Features

  • MQTT v3.1.1 and v5 protocols, a single server can serve both
  • Client and server
  • QoS 0, 1 and 2
  • Streaming publish payloads, large messages are processed in chunks
  • Flow control: receive maximum, in-flight size limits and read pause
  • Topic routing and v5 topic aliases
  • TLS (openssl, rustls) via ntex-tls, and MQTT over WebSocket

Installation

[dependencies]
ntex = "4"
ntex-mqtt = "9"

Server

use ntex::SharedCfg;
use ntex_mqtt::{MqttServer, v3, v5};

#[derive(Debug)]
struct Error;

impl From<()> for Error {
    fn from(_: ()) -> Self {
        Error
    }
}

impl TryFrom<Error> for v5::PublishAck {
    type Error = Error;

    fn try_from(err: Error) -> Result<Self, Self::Error> {
        Err(err)
    }
}

#[ntex::main]
async fn main() -> std::io::Result<()> {
    ntex::server::build()
        .bind("mqtt", "127.0.0.1:1883", SharedCfg::default(), async |_| {
            MqttServer::new()
                .v3(
                    v3::MqttServer::new(async |pkt: v3::Publish| {
                        println!("v3 publish: {}", pkt.topic().path());
                        Ok::<_, Error>(())
                    })
                    .build(async |con: v3::Connect| Ok::<_, Error>(con.ack((), false))),
                )
                .v5(
                    v5::MqttServer::new(async |pkt: v5::Publish| {
                        println!("v5 publish: {}", pkt.topic().path());
                        Ok::<_, Error>(pkt.ack())
                    })
                    .build(async |con: v5::Connect| Ok::<_, Error>(con.ack(()))),
                )
        })?
        .run()
        .await
}

Client

use ntex::{Pipeline, SharedCfg, util::Bytes};
use ntex_mqtt::v3;

#[ntex::main]
async fn main() {
    let client = Pipeline::new(SharedCfg::default(), v3::client::MqttConnector::new())
        .call(v3::client::Connect::new("127.0.0.1:1883").client_id("my-client"))
        .await
        .unwrap();

    let sink = client.sink();
    ntex::rt::spawn(client.start_default());

    sink.publish("topic")
        .send_at_least_once(Bytes::from_static(b"hello"))
        .await
        .unwrap();
    sink.close();
}

Links

License

This project is licensed under either of

at your option.

Explorar proyectos relacionados

Cargando…