background

Apache RocketMQ is a distributed messaging and streaming platform with low latency, high performance and reliability, trillion-level capacity and flexible scalability.

The configuration of Huawei Yunkunpeng server used in the experiment is as follows:

Huawei Kunpeng 920 2.6 GHz four vcpus openEuler | 8 gb 20.03 64 - bit with ARMCopy the code

After connecting to the host, check the system information. Note that the software package is aARCH64, and the software package must be aARCH64.

# Check system kernel information
[root@ecs-kunpeng-0005 ~]# uname -aLinux ecs - 4.19.90 kunpeng - 0005-2003.4.0.0036. Oe1. Aarch64#1 SMP Mon Mar 23 19:06:43 UTC 2020 aarch64 aarch64 aarch64 GNU/Linux

# Check the system version information
[root@ecs-kunpeng-0005 ~]# cat /etc/os-release
NAME="openEuler"
VERSION="20.03 (LTS)"
ID="openEuler"
VERSION_ID="20.03"
PRETTY_NAME="openEuler 20.03 (LTS)"
ANSI_COLOR="0; 31"
Copy the code

Check the environment

RocketMQ is implemented in Java, so a Java environment is required first, while openEuler 20.03 64bit with ARM comes preloaded with Java8 by default.

[root@ecs-kunpeng-0005 ~]# java -version
openjdk version "1.8.0 comes with _242"
OpenJDK Runtime Environment (build 1.8.0_242-b08)
OpenJDK 64-Bit Server VM (build 25.242-b08, mixed mode)
Copy the code

Install RocketMQ

  • Download: www.apache.org/dyn/closer….
# decompression
[root@ecs-kunpeng-0006 local]# unzip rocketmq - all - 4.7.1 - bin - release. Zip
[root@ecs-kunpeng-0006 local]# mv rocketmq - all - 4.7.1 - bin - release rocketmq
[root@ecs-kunpeng-0006 local]# cd rocketmq

Start nameserver
[root@ecs-kunpeng-0006 rocketmq]# nohup sh bin/mqnamesrv &
View the Nameserver startup log
[root@ecs-kunpeng-0006 rocketmq]# tail -f ~/logs/rocketmqlogs/namesrv.log
# Check nameserver process
[root@ecs-kunpeng-0006 rocketmq]# jps
1557947 Jps
230238 NamesrvStartup

# start the broker
[root@ecs-kunpeng-0006 rocketmq]# bin/mqbroker -n localhost:9876
Copy the code
  • Error 1: Starting the Broker failed:

    Error: VM option ‘UseG1GC’ is experimental and must be enabled via -XX:+UnlockExperimentalVMOptions. Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit.

  • Solution: If you look at the bin/mqbroker script, which calls runbroker.sh, edit runbroker.sh and find the UseG1GC option (experimental option), delete this line.

Delete the configuration line containing UseG1GC
[root@ecs-kunpeng-0006 rocketmq]# vi bin/runbroker.sh
JAVA_OPT="${JAVA_OPT} -XX:+UseG1GC -XX:G1HeapRegionSize=16m -XX:G1ReservePercent=25 -XX:InitiatingHeapOccupancyPercent=30 -XX:SoftRefLRUPolicyMSPerMB=0"
Copy the code
  • Question 2:

    There is insufficient memory for the Java Runtime Environment to continue. Native memory allocation (mmap) failed to map 8589934592 bytes for committing reserved memory. An error report file with more information is saved as: /usr/local/rocketmq/bin/hs_err_pid10503.log

# editor runbroker. Sh
[root@ecs-kunpeng-0006 rocketmq]# vi bin/runbroker.sh
JAVA_OPT="${JAVA_OPT} -server -Xms8g -Xmx8g -Xmn4g"Change the value to JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx256m -Xmn128m"

# Try to restart
[root@ecs-kunpeng-0006 rocketmq]# bin/mqbroker -n localhost:9876The broker[ECS-kunpeng-0006, 172.17.0.1:10911] Boot Success. SerializeType =JSON and name server is localhost:9876# check the process
[root@ecs-kunpeng-0006 rocketmq]# jps
1657041 BrokerStartup
1659988 Jps
230238 NamesrvStartup
Copy the code
  • Fault 3: Access from the public network is unavailable after the previous step is started

If RocketMQ is deployed on a public network and needs to be accessed from an external network, perform the following operations.

# 1. Add to conf/broker.conf:
[root@ecs-kunpeng-0006 rocketmq]# vi conf/broker.confBrokerIP1 = your public IP address# 2. Start the broker with this command:
[root@ecs-kunpeng-0006 rocketmq]# bin/mqbroker -n Your public IP address: 9876-c conf/broker.confThe broker[broker-a, your public IP:10911] boot Success. SerializeType =JSON and name server is your public IP:9876Remote client error:
org.apache.rocketmq.remoting.exception.RemotingTooMuchRequestException: sendDefaultImpl call timeout
Copy the code

Springboot-based remote client

  1. Add dependencies to pom.xml
<dependency>
    <groupId>org.apache.rocketmq</groupId>
    <artifactId>rocketmq-client</artifactId>
    <version>4.7.1</version>
</dependency>
Copy the code
  1. Writing test classes
@RunWith(SpringRunner.class)
@SpringBootTest
public class SpringbootRocketProducerApplicationTests {
    @Test
    public void producer(a) throws MQClientException, RemotingException, InterruptedException, MQBrokerException {
        DefaultMQProducer producer = new DefaultMQProducer("my-producer");
        producer.setNamesrvAddr(Your public IP address :9876);
        producer.start();

        Message message = new Message("myTopic01"."Hello RocketMQ!".getBytes());
        SendResult sendResult = producer.send(message);
        System.out.println("Message send Success, result: " + sendResult);

        producer.shutdown();
        System.out.println("Producer shutdown!");
    }
Copy the code
  1. Run test method
  • No route info of this topic: myTopic01

  • Solution: Configure the automatic creation of the broker when it is started with the parameter autoCreateTopicEnable=true

AutoCreateTopicEnable =true
[root@ecs-kunpeng-0006 rocketmq]# bin/mqbroker -n Your public IP address :9876 -c conf/broker.conf autoCreateTopicEnable=true
Copy the code
  1. Verify that the topic was created successfully and that the test message was sent successfully

You can use the RocketMQ official Web management console. Download: github.com/apache/rock… , is itself a SpringBoot-based Web project, modified to its own RocketMQ address before starting, running on port 8080 by default.

Start broker in the background

# background boot
[root@ecs-kunpeng-0006 rocketmq]# nohup sh bin/mqbroker -n Your public IP address :9876 -c conf/broker.conf autoCreateTopicEnable=true &

View the startup log
[root@ecs-kunpeng-0006 rocketmq]# tail -f ~/logs/rocketmqlogs/broker.log

# Check the startup process
[root@ecs-kunpeng-0006 rocketmq]# jps
1971242 BrokerStartup
1972997 Jps
230238 NamesrvStartup
Copy the code

How to Stop Gracefully

[root@ecs-kunpeng-0006 rocketmq]# sh bin/mqshutdown broker
[root@ecs-kunpeng-0006 rocketmq]# sh bin/mqshutdown namesrv
Copy the code

Reference

  • Huawei Official Image
  • RPM is an official Huawei image
  • RocketMQ official documentation

If you have any questions or any bugs are found, please feel free to contact me.

Your comments and suggestions are welcome!

This article has participated in the activity of “New person creation Ceremony”, and started the road of digging gold creation together.