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
    1. NameServer stores the mapping between topic and broker addresses. NameServer stores the mapping between topic and broker addresses.
    2. Provide a broker address for a topic for a producer or consumer to send or consume messages.
    3. 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
    1. Configure the environment variable ROCKETMQ_HOME= your file path/RocketMQ /distribution;
    2. Find the org. Apache. Rocketmq. Namesrv. NamesrvStartup start main method;
    3. The console prints a success statement;
  • Start theBroker
    1. In addition to ROCKETMQ_HOME, you need to configure a NAMESRV_ADDR. The default is localhost:9876;
    2. Find the org. Apache. Rocketmq. Broker. BrokerStartup start main method;
    3. The console prints a success statement;
  • Start theConsumer
    1. Find the org. Apache. Rocketmq. Example. Quickstart. Consumer;
    2. If you use your own NAMESRV_ADDR then you need to modify the code in the main method to set nameSrvAddr;
    3. Start the main method, listen for messages, if there are already unconsumed messages, will start consuming;
  • Start theProducer
    1. Find the org. Apache. Rocketmq. Example. Quickstart. Producer;
    2. If you use your own NAMESRV_ADDR then you need to modify the code in the main method to set nameSrvAddr;
    3. 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

  1. Download rocketMq-Externals project;
  2. Start the RocketMQ-Console module;
  3. 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;