preface

In this article, we have analyzed how NameServer is started. In this article, we will analyze how the Broker registers messages and sends heartbeat maintenance messages to NameServer. To consolidate the content of the previous article, see the following figure

When NameServer is started, it has a Netty server listening for port 9876, and then other clients can use this port to communicate with each other

Broker startup script

As you have seen in previous articles, NameServer is started. The Broker is also used to set the PARAMETERS of the JVM process through a script file, and then find the start class to execute the main() method.

Second, the BrokerStartup

This will look familiar to you from my previous NameServer startup article, but it’s all the same, so let’s go straight to how createBrokerController is created

BrokerController’s four core classes

NettyServerConfig and NettyClientConfig create two Netty’s. Why is there only one NameSever? In fact, NameServer just receives the request and returns the information. A Broker sends messages, configures them in a NameServer, and acts as a server to receive message requests from consumers and producers. This is a lot of code to create the four core components used to start the Broker, with an image that will be used later

These core points have been explained, the rest of the extra code is not clear, you can see for yourself. Is related to printing log information, is not the focus of this article

BrokerController Creation

After the previous code has created the four core classes, it’s time to construct the Controller object

As is clear from the diagram above, the Broker is started with a script and then invokes BrokerStartup to create the four core components and then configure the BrokerController object. Ultimately clients interact with BrokerControllers, so there is some core component functionality, and then the broker’s data store needs some background thread pool running.

Initialize controller initialize()

Just capture some of the code above, are the main several thread pool to create different requests for different thread pool, because the broker was sent to the NameServer, still needs to receive the request of the consumer and producer, and high availability of news measures, as well as some background related tasks of the timing schedule is also a thread pool to ensure operation

conclusion

You want to have an image of the initialization, which is essentially creating a Controller object with a few core components. Because BrokerController deals with NameServer so it uses The NettyClient and also makes sure that the client requests to BrokerController have the NettyServer receive the requests, has some functionality to request pull messages and so forth thread pool, Finally, there are some background timing threads that keep the Broker running.

Write at the end, thanks for the likes

Welcome to follow my wechat official account [Village of the Apes]

To talk about Java interview and my wechat further communication and learning, wechat mobile search [codeYuanzhicunup] can be added if there are related technical problems welcome to leave a message to discuss, the public number is mainly used for technology sharing, including often meet test analysis, as well as source code interpretation, micro service framework, technical hot spots, etc..