Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to analyze the moqutte source code of broker in mqtt protocol

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

It is believed that many inexperienced people have no idea about how to analyze the moqutte source code of broker in mqtt protocol. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

There are many broker of mqtt protocol, but not many of java support clusters. After a survey before, I found that moqutte basically meets the needs, so I want to do my own secondary development based on this.

Github address: https://github.com/andsel/moquette

one. Pour code into idea

Find the startup class

Start the error because the configuration file for moquette could not be found

The configuration file address of the tracking source code moquette is config/moquette.conf

Because we started the main method in the Server class directly, rather than the jar package packaged through assebely, all of this location does not have a configuration file, but moquette supports specifying the location of the configuration file through startup parameters

That's easy. Put the configuration file needed for startup somewhere locally and specify it through the startup parameters. Specify it in idea.

I put it in the / data/moquette directory

In addition, the configuration files needed for idea startup are included in the config package under the broker module, or distribution/src/main/resources

Started successfully after joining

two. Configuration file explanation

There are five configuration files for moqutte. Let's explain the function of each one.

The main configuration file of 1.moquette.conf and the main configuration needed for moquette startup are all here, including port number, authentication, storage, etc. The meaning of each parameter will be explained in detail when explaining the source code later.

The cluster of 2.hazelcast.xml moquette is realized through .hazelcast. Students who don't know can google it on their own, so I won't go into details here.

3.password_file.conf, what is configured here is the password required for the connection.

4.acl.conf, this is the read and write permission of each client to topic.

5.log4j.properties log file, say no more

three. The client chooses. I choose the paha,github address https://github.com/eclipse/paho.mqtt.java of eclipse.

After pouring into idea, find the following test class

At the break point on the io.moquette.server.netty.NettyMQTTHandler class of moquette, restart

Start the test class of paha and start the test

It is found that the breakpoint of moquette has come in, indicating that the link from client to broker is open, and then the source code can be tracked.

The reason for this breakpoint is that this is the access point between netty and other applications. Students who know about netty should know that applications only need to implement a handler. When there is data flow, netty is responsible for calling back your handler.

After reading the above, do you know how to analyze the moqutte source code of broker in mqtt protocol? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report