Content abstract
- A brief introduction to rocketMQ architecture design;
- Build RocketMQ service locally based on IDEA to realize local production and consumption function;
- Rocketmq-console is deployed to build a visual management terminal.
Architectural design for RocketMQ
Rocketmq has four main parts architecturally, as shown in the figure above (each part is deployed in cluster mode) :
- NameServer: Route registry, which supports dynamic registration and discovery
- NameServer stores the mapping between topic and broker addresses. NameServer stores the mapping between topic and broker addresses.
- Provide a broker address for a topic for a producer or consumer to send or consume messages.
- Provides a registration interface for brokers to register their own routing information and a heartbeat interface to detect the survival status of brokers.
- Broker: Stores, delivers, and queries messages.
- Producer: a Producer of messages that delivers messages to brokers;
- Consumer: message consumers who obtain messages from brokers and consume them;
Service startup process based on IDEA
Environment to prepare
- Install the JDK and Maven environment.
- Download the RocketMQ source code from Github;
Service Startup process
- Start theNameServer
- Configure the environment variable ROCKETMQ_HOME= your file path/RocketMQ /distribution;
- Find the org. Apache. Rocketmq. Namesrv. NamesrvStartup start main method;
- The console prints a success statement;
- Start theBroker
- In addition to ROCKETMQ_HOME, you need to configure a NAMESRV_ADDR. The default is localhost:9876;
- Find the org. Apache. Rocketmq. Broker. BrokerStartup start main method;
- The console prints a success statement;
- Start theConsumer
- Find the org. Apache. Rocketmq. Example. Quickstart. Consumer;
- If you use your own NAMESRV_ADDR then you need to modify the code in the main method to set nameSrvAddr;
- Start the main method, listen for messages, if there are already unconsumed messages, will start consuming;
- Start theProducer
- Find the org. Apache. Rocketmq. Example. Quickstart. Producer;
- If you use your own NAMESRV_ADDR then you need to modify the code in the main method to set nameSrvAddr;
- In main, there is a for loop that sends 1000 messages, and the number of times can be changed. If the main method is started, messages will be sent to the test topic. If the consumer is started, the messages sent at this time will be consumed.
The NameServer must be started first in the startup process, and then the broker must be started to register routing information with the NameServer. Subsequent Consmer and producer have no order requirements;
Deploying the Visual Console
- Download rocketMq-Externals project;
- Start the RocketMQ-Console module;
- Access localhost:8080(the default) and see the RocketMQ console. The default connection is NameServerAddr=localhost:9876;
summary
This is the end of this article, mainly based on IDEA to build mq local services, easy to debug code to help learn the source code, will be introduced one by one rocketMQ components;