First, build the source reading environment

There are many useful tutorials on the Internet, so I won’t repeat them. You can refer to: www.cnblogs.com/heliusKing/…

One thing I need to remind you about this tutorial is: note the configuration in the image, and change the path to your actual path

Two, the opening paragraph must read

2.1 What to Prepare before reading the source code

If you have never worked with RocketMQ before, it is highly recommended that you read through the documentation on the RocketMQ website first, focusing on the “Concepts and features”, “Architecture design” two parts, the following several parts are practical, you can ignore or skim.

For those of you who have studied and used RocketMQ before, you can read it directly, but if you want to review the concepts, you can also take the time to read the official documentation first.

2.2 How to Read

Source directory structure:

  • Broker: Broker module (broke starts the process) ☆
  • Client: message client, including message producer, message consumer related classes ☆
  • Common: Public package
  • Dev: Developer information (not source code)
  • Distribution: Deployment instance folder (non-source)
  • Example: RocketMQ example code
  • Filter: basic class related to message filtering
  • Filtersrv: Message filtering server implementation related class (Filter start process)
  • Logappender: Log implementation related classes
  • Namesrv: NameServer implements the related class (NameServer starts the process) ☆
  • Openmessageing: An open standard for messaging
  • Remoting: Remote communication module, based on Netty
  • Srcutil: Service utility class
  • Store: Message storage implementation related classes ☆
  • Style: checkStyle Related implementation
  • Test: Tests related classes
  • Tools: tools class, monitoring command related implementation class

The modules we need to focus on have been marked with ☆

Code:

At around 100,000 lines of source code, that’s not a lot, but don’t panic, because in reality, the core code isn’t much

2.2 Principles and Ideas

Principle 1: Read the source code with the problem

This I think is very important, no problem, just throw you a project source code, do not know where to start. So over the course of this series, I’ll keep asking questions, and then take them to the source code for answers.

Principle 2: One path to the end

Following a process, we should go to the end of the process to form a complete thinking chain, which is also very important for building a knowledge framework. Otherwise, a hoe in the east and a sickle in the west are all fragments of knowledge, not a system.

Principle 3: First the whole, then the details

First read the key steps of the overall process and clarify the logic. Then dig a little deeper for some of the details that are valuable. Valuable details, I must emphasize. Don’t get bogged down in irrelevant code details and think you don’t know it. In fact, it is not necessary, knowledge is endless, there are always knowledge points we do not know. What we should do is to spend our limited time on the study of the knowledge that is most valuable to us.

Train of thought

The overall message body follows the entire life cycle of the message from being sent to being stored to being consumed.

2.3 Writing Methods

Although this is a source reading article, I’m not going to post large chunks of code into the article that are too long and meaningless. Instead, I map out the timing of key processes and post code to analyze and discuss key details. With the help of time sequence diagrams, I believe that readers will be able to read the RocketMQ source code more efficiently on their own