Skip to content
Projets

À propos

Framework client/serveur MQTT pour les protocoles v5 et v3.1.1.

Systèmes et infrastructure

Comment ces chiffres sont mesurés

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

Progression mesurée des étoiles

in 24h
0
in 7 days
0
in 15 days
0
in 1 month
Historique en cours

Variations nettes sur des périodes qui se chevauchent, pas des totaux quotidiens. Les mesures absentes restent vides. Les étoiles indiquent l’intérêt, pas la qualité.

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.

Explorer des projets similaires

Chargement…