项目作者: mobius-software-ltd

项目描述 :
MQTT packets and headers parser library based on netty
高级语言: Java
项目地址: git://github.com/mobius-software-ltd/mqtt-parser.git
创建时间: 2016-09-26T09:21:22Z
项目社区:https://github.com/mobius-software-ltd/mqtt-parser

开源协议:Other

下载


MQTT parser

MQTT parser is a library designed for encoding and decoding of MQTT 3.1.1 packets. It is written in Java. MQTT parser is developed by Mobius Software.

Getting Started

First you should clone MQTT parser. Then you should add the following lines within the element of pom.xml file of your project:

  1. <dependency>
  2. <groupId>com.mobius.software.mqtt</groupId>
  3. <artifactId>parser</artifactId>
  4. <version>0.0.1-SNAPSHOT</version>
  5. </dependency>

Now you are able to start using MQTT parser.

Examples

Create, encode, decode message

  1. try
  2. {
  3. // Message creation
  4. String username = "foo@bar.net";
  5. String password = "password";
  6. String clientID = "dummy-client-1";
  7. boolean cleanSession = true;
  8. int keepalive = 10;
  9. Text topicName = new Text("root/example");
  10. Topic topic = Topic.valueOf(topicName, QoS.AT_LEAST_ONCE);
  11. String content = "message";
  12. boolean retain = false;
  13. Will will = new Will(topic, content.getBytes(), retain);
  14. Connect connect = new Connect(username, password, clientID, cleanSession, keepalive, will);
  15. // Encode message
  16. ByteBuf encoded = MQParser.encode(connect);
  17. // process encoded value...
  18. // Decode message
  19. MQMessage decoded = MQParser.decode(encoded);
  20. // process decoded value...
  21. }
  22. catch (Exception e)
  23. {
  24. e.printStackTrace();
  25. fail();
  26. }