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
The most scalable and reliable MQTT broker for AI, IoT, IIoT and connected vehicles
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
- Creating an MQTT client and connecting to a broker:
MqttClient client = new MqttClient("tcp://broker.hivemq.com:1883", MqttClient.generateClientId());
client.connect();
- Publishing a message:
String topic = "test/topic";
String payload = "Hello, MQTT!";
MqttMessage message = new MqttMessage(payload.getBytes());
client.publish(topic, message);
- Subscribing to a topic:
client.subscribe("test/topic", (topic, message) -> {
System.out.println("Received message: " + new String(message.getPayload()));
});
- Disconnecting from the broker:
client.disconnect();
client.close();
Getting Started
To use the mcxiaoke/mqtt library in your Java project:
- 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>
- Import the necessary classes in your Java file:
import com.github.mcxiaoke.mqtt.MqttClient;
import com.github.mcxiaoke.mqtt.MqttMessage;
- 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.
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.
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
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
MQTTåè®®ä¸æç
by mcxiaoke
ææ°çæ¬: v1.0.6 2021.07.07
ææ¡£å°å
æ¦è¿°
MQTTæ¯ä¸ä¸ªå®¢æ·ç«¯æå¡ç«¯æ¶æçåå¸/è®¢é æ¨¡å¼çæ¶æ¯ä¼ è¾åè®®ãå®çè®¾è®¡ææ³æ¯è½»å·§ã弿¾ãç®åãè§èï¼æäºå®ç°ãè¿äºç¹ç¹ä½¿å¾å®å¯¹å¾å¤åºæ¯æ¥è¯´é½æ¯å¾å¥½çéæ©ï¼ç¹å«æ¯å¯¹äºåéçç¯å¢å¦æºå¨ä¸æºå¨çéä¿¡ï¼M2Mï¼ä»¥åç©èç½ç¯å¢ï¼IoTï¼ã
ç®å½
åç°ä»»ä½ç¿»è¯é®é¢ææ ¼å¼é®é¢æ¬¢è¿æPR帮å¿å®åã
- 说æ
- åè¨
- ç®å½
- 第ä¸ç« - MQTTä»ç»
- 第äºç« â MQTTæ§å¶æ¥ææ ¼å¼
- 第ä¸ç« â MQTTæ§å¶æ¥æ
- 3.1 CONNECT â è¿æ¥æå¡ç«¯
- 3.2 CONNACK â ç¡®è®¤è¿æ¥è¯·æ±
- 3.3 PUBLISH â å叿¶æ¯
- 3.4 PUBACK âåå¸ç¡®è®¤
- 3.5 PUBREC â å叿¶å°ï¼QoS 2ï¼ç¬¬ä¸æ¥ï¼
- 3.6 PUBREL â åå¸éæ¾ï¼QoS 2ï¼ç¬¬äºæ¥ï¼
- 3.7 PUBCOMP â åå¸å®æï¼QoS 2ï¼ç¬¬ä¸æ¥ï¼
- 3.8 SUBSCRIBE - 订é 主é¢
- 3.9 SUBACK â 订é 确认
- 3.10 UNSUBSCRIBE âåæ¶è®¢é
- 3.11 UNSUBACK â åæ¶è®¢é 确认
- 3.12 PINGREQ â å¿è·³è¯·æ±
- 3.13 PINGRESP â å¿è·³ååº
- 3.14 DISCONNECT âæå¼è¿æ¥
- 第åç« â æä½è¡ä¸º
- 第äºç« â å®å ¨
- 第å ç« â 使ç¨WebSocket
- 第ä¸ç« â ä¸è´æ§ç®æ
- éå½B - å¼ºå¶æ§è§è声æ
æ§çææ¡£
å·²è¿æï¼å»ºè®®ä½¿ç¨GitBookçæ¬ ææ°çæ¬: v1.0.1 2015.10.22
ææ¡£ | è¿æ¥ |
---|---|
䏿ç HTML | MQTT 3.1.1 䏿ç |
䏿ç PDF | MQTT 3.1.1 䏿ç |
è±æç HTML | MQTT Version 3.1.1 |
è±æç PDF | MQTT Version 3.1.1 |
许å¯åè®®
èç³»æ¹å¼
- Blog: http://blog.mcxiaoke.com
- Github: https://github.com/mcxiaoke
- Email: github@mcxiaoke.com
弿ºé¡¹ç®
- MQTT WebClient: https://github.com/mcxiaoke/mqtt-monitor
- Rxææ¡£ä¸æç¿»è¯: https://github.com/mcxiaoke/RxDocs
- MQTTåè®®ä¸æç: https://github.com/mcxiaoke/mqtt
- Awesome-Kotlin: https://github.com/mcxiaoke/awesome-kotlin
- Kotlin-Koi: https://github.com/mcxiaoke/kotlin-koi
- Nextå ¬å ±ç»ä»¶åº: https://github.com/mcxiaoke/Android-Next
- PackerNgæéæå : https://github.com/mcxiaoke/packer-ng-plugin
- Gradleæ¸ éæå : https://github.com/mcxiaoke/gradle-packer-plugin
- EventBuså®ç°xBus: https://github.com/mcxiaoke/xBus
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
The most scalable and reliable MQTT broker for AI, IoT, IIoT and connected vehicles
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!
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot