Convert Figma logo to code with AI

mcxiaoke logomqtt

MQTT协议3.1.1中文翻译版,IoT,物联网

5,105
1,226
5,105
2

Top Related Projects

paho.mqtt.python

Eclipse Mosquitto - An open source MQTT broker

HiveMQ CE is a Java-based open source MQTT broker that fully supports MQTT 3.x and MQTT 5. It is the foundation of the HiveMQ Enterprise Connectivity and Messaging Platform

15,076

The most scalable and reliable MQTT broker for AI, IoT, IIoT and connected vehicles

3,369

A distributed MQTT message broker based on Erlang/OTP. Built for high quality & Industrial use cases. The VerneMQ mission is active & the project maintained. Thank you for your support!

Quick Overview

The mcxiaoke/mqtt repository is a Java implementation of the MQTT (Message Queuing Telemetry Transport) protocol. It provides a lightweight and efficient client library for MQTT communication, suitable for IoT (Internet of Things) and mobile applications.

Pros

  • Lightweight and easy to integrate into Java projects
  • Supports MQTT versions 3.1 and 3.1.1
  • Provides both synchronous and asynchronous APIs
  • Well-documented with clear examples

Cons

  • Not actively maintained (last commit was in 2017)
  • Lacks support for MQTT 5.0
  • Limited features compared to more modern MQTT libraries
  • May have compatibility issues with newer Java versions

Code Examples

  1. Creating an MQTT client and connecting to a broker:
MqttClient client = new MqttClient("tcp://broker.hivemq.com:1883", MqttClient.generateClientId());
client.connect();
  1. Publishing a message:
String topic = "test/topic";
String payload = "Hello, MQTT!";
MqttMessage message = new MqttMessage(payload.getBytes());
client.publish(topic, message);
  1. Subscribing to a topic:
client.subscribe("test/topic", (topic, message) -> {
    System.out.println("Received message: " + new String(message.getPayload()));
});
  1. Disconnecting from the broker:
client.disconnect();
client.close();

Getting Started

To use the mcxiaoke/mqtt library in your Java project:

  1. Add the following dependency to your pom.xml file:
<dependency>
    <groupId>com.github.mcxiaoke</groupId>
    <artifactId>mqtt-client</artifactId>
    <version>1.2.0</version>
</dependency>
  1. Import the necessary classes in your Java file:
import com.github.mcxiaoke.mqtt.MqttClient;
import com.github.mcxiaoke.mqtt.MqttMessage;
  1. Create an MQTT client, connect to a broker, and start publishing or subscribing to topics as shown in the code examples above.

Competitor Comparisons

paho.mqtt.python

Pros of paho.mqtt.python

  • More actively maintained with regular updates and bug fixes
  • Comprehensive documentation and examples
  • Supports both MQTT v3.1.1 and v5.0 protocols

Cons of paho.mqtt.python

  • Larger codebase, potentially more complex for simple use cases
  • Requires additional dependencies for certain features

Code Comparison

paho.mqtt.python:

import paho.mqtt.client as mqtt

client = mqtt.Client()
client.connect("broker.hivemq.com", 1883, 60)
client.publish("topic", "message")
client.loop_forever()

mqtt:

from mqtt import MQTTClient

client = MQTTClient("broker.hivemq.com", 1883)
client.connect()
client.publish("topic", "message")
client.loop_forever()

The code snippets show that paho.mqtt.python uses a slightly different approach to creating and connecting the client, while mqtt provides a more streamlined interface. However, both libraries offer similar core functionality for publishing messages to an MQTT broker.

Eclipse Mosquitto - An open source MQTT broker

Pros of Mosquitto

  • More mature and widely adopted project with extensive documentation
  • Supports a broader range of MQTT features and versions
  • Offers both server and client implementations

Cons of Mosquitto

  • Larger codebase and potentially more complex to understand
  • Written in C, which may be less accessible for some developers

Code Comparison

Mosquitto (C):

int mosquitto_publish(struct mosquitto *mosq, int *mid, const char *topic, int payloadlen, const void *payload, int qos, bool retain)
{
    return mosquitto_publish_v5(mosq, mid, topic, payloadlen, payload, qos, retain, NULL);
}

MQTT (Java):

public void publish(String topic, byte[] payload, int qos, boolean retained) throws MqttException {
    MqttMessage message = new MqttMessage(payload);
    message.setQos(qos);
    message.setRetained(retained);
    client.publish(topic, message);
}

Summary

Mosquitto is a more comprehensive MQTT implementation with broader feature support and a mature ecosystem. It's written in C and provides both server and client functionality. MQTT, on the other hand, is a Java-based client implementation that may be easier to integrate into Java projects but offers fewer features. The choice between them depends on specific project requirements, language preferences, and the need for server-side functionality.

HiveMQ CE is a Java-based open source MQTT broker that fully supports MQTT 3.x and MQTT 5. It is the foundation of the HiveMQ Enterprise Connectivity and Messaging Platform

Pros of HiveMQ Community Edition

  • Full-featured MQTT broker with enterprise-grade capabilities
  • Scalable architecture supporting high-throughput messaging
  • Active development and community support

Cons of HiveMQ Community Edition

  • More complex setup and configuration
  • Higher resource requirements for deployment
  • Steeper learning curve for beginners

Code Comparison

MQTT (Java):

MqttClient client = new MqttClient("tcp://iot.eclipse.org:1883", clientId);
MqttConnectOptions options = new MqttConnectOptions();
options.setCleanSession(true);
client.connect(options);

HiveMQ Community Edition (Java):

Mqtt5BlockingClient client = Mqtt5Client.builder()
    .serverHost("localhost")
    .buildBlocking();
client.connect();

The MQTT library provides a more straightforward client setup, while HiveMQ offers a builder pattern for configuration. HiveMQ's approach allows for more flexible and extensible client creation, but may require more code for basic usage.

MQTT is a lightweight MQTT client library, suitable for simple implementations and resource-constrained environments. HiveMQ Community Edition is a full-featured MQTT broker with additional capabilities, making it more suitable for large-scale, enterprise-grade deployments. The choice between the two depends on the specific requirements of your project, such as scalability needs, available resources, and desired features.

15,076

The most scalable and reliable MQTT broker for AI, IoT, IIoT and connected vehicles

Pros of EMQX

  • More active development with frequent updates and releases
  • Scalable and distributed architecture for high-performance MQTT broker
  • Comprehensive features including clustering, authentication, and rule engine

Cons of EMQX

  • More complex setup and configuration
  • Steeper learning curve for beginners
  • Requires more system resources due to its enterprise-grade features

Code Comparison

EMQX (Erlang):

-module(emqx_broker).
-export([publish/1]).

publish(Message) ->
    emqx:publish(Message).

MQTT (Java):

public class MqttPublisher {
    public void publish(MqttMessage message) {
        client.publish(topic, message);
    }
}

Key Differences

  • EMQX is a full-featured MQTT broker, while MQTT is a client library
  • EMQX is written in Erlang, focusing on scalability and distributed systems
  • MQTT is a Java implementation, suitable for Android and Java applications
  • EMQX offers more advanced features like clustering and rule engine
  • MQTT provides a simpler, lightweight client-side implementation

Use Cases

  • EMQX: Enterprise IoT deployments, large-scale messaging systems
  • MQTT: Android apps, Java-based IoT devices, simpler MQTT client needs

Both projects serve different purposes in the MQTT ecosystem, with EMQX being a robust broker solution and MQTT offering a client-side library for Java environments.

3,369

A distributed MQTT message broker based on Erlang/OTP. Built for high quality & Industrial use cases. The VerneMQ mission is active & the project maintained. Thank you for your support!

Pros of VerneMQ

  • Highly scalable and distributed MQTT broker
  • Built-in clustering support for high availability
  • Extensive plugin system for customization and integration

Cons of VerneMQ

  • More complex setup and configuration
  • Heavier resource usage due to its distributed nature
  • Steeper learning curve for beginners

Code Comparison

VerneMQ (Erlang):

-module(vmq_server).
-export([start/0, stop/0]).

start() ->
    application:ensure_all_started(vmq_server).

stop() ->
    application:stop(vmq_server).

MQTT (Java):

public class MqttClient {
    public void connect(String broker, int port) {
        // Connection logic
    }
    public void publish(String topic, String message) {
        // Publishing logic
    }
}

Summary

VerneMQ is a robust, scalable MQTT broker designed for enterprise-level deployments, offering clustering and extensive customization options. MQTT, on the other hand, is a simpler Java-based MQTT client library, suitable for smaller projects or client-side implementations. VerneMQ provides a more comprehensive solution for building large-scale MQTT systems, while MQTT offers a straightforward client implementation for Java applications.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

MQTT协议中文版

by mcxiaoke

最新版本: v1.0.6 2021.07.07

文档地址

概述

MQTT是一个客户端服务端架构的发布/订阅模式的消息传输协议。它的设计思想是轻巧、开放、简单、规范,易于实现。这些特点使得它对很多场景来说都是很好的选择,特别是对于受限的环境如机器与机器的通信(M2M)以及物联网环境(IoT)。

目录

发现任何翻译问题或格式问题欢迎提PR帮忙完善。


旧版文档

已过期,建议使用GitBook版本 最新版本: v1.0.1 2015.10.22

文档连接
中文版 HTMLMQTT 3.1.1 中文版
中文版 PDFMQTT 3.1.1 中文版
英文版 HTMLMQTT Version 3.1.1
英文版 PDFMQTT Version 3.1.1

许可协议


联系方式

开源项目