current position:Home>Ten minutes to understand rocketmq and installation application

Ten minutes to understand rocketmq and installation application

2022-01-27 02:30:12 There are people on the mountain

RocketMQ Introduce

Message Queuing Middleware is an important component of distributed system , Mainly solve application coupling , Asynchronous messaging , Flow cutting
Achieve high performance , High availability , Scalable and ultimately consistent architecture . Many message queues are ActiveMQ,RabbitMQ,ZeroMQ,Kafka,MetaMQ,RocketMQ, Let's focus on RocketMQ Construction and use of .RocketMQ It is a message middleware of queue model developed by Ali , Open source to apache The foundation became apache Top open source projects , High performance 、 Highly reliable 、 High real time 、 Distributed features .

Application scenarios

Message queuing is widely used in the development of Internet technology , It is mainly used to solve the problem of application coupling , Message delivery , Flow cutting . The following describes the common use scenarios of message queuing in practical applications ( Take the user's order as an example ).

The application of decoupling

The scene that : A simple scenario in which users increase their points according to the payment amount after placing an order , In the traditional mode, the order module needs to call the integral module interface , In this way, the order module and the integral module form a system coupling , Once the integral module is modified or abnormal, it will affect the function of the order module . After introducing the message queue scheme , After the user orders successfully , Just write the message to the message queue . The point module only needs to subscribe to the order message , Get data from the message queue for consumption , In this way, the order module and integral module only need to focus on realizing their own functions , Realize decoupling .

Data dissemination

The scene that : After the user places an order, the log module shall record the order log , The inventory module needs to reduce the corresponding inventory , The integration module needs to add user points and other business operations of other modules caused by the success of the order , At this time, the message queue can make the data flow more among multiple systems . Data producers don't need to care who uses the data , Just send the data to the message queue , The data user can get the data directly in the message queue .

Peak shaving and valley filling

The scene that : The request traffic received by the system soared during the double 11 , It's possible to crush the system . The traditional approach is to ensure the stability of the system , Generally, the server configuration is increased 、 Load balancing for new servers is a waste of server performance when the service can be met in normal time , It's not worth it ! Another approach is if the system load exceeds the threshold , Will prevent the user from requesting , But this can affect the user experience during peak traffic . This problem can be solved perfectly through message queuing , After the introduction of message queuing scheme, a large number of requests can be cached , Spread over a long period of time , This can greatly mention the stability of the system and the user experience .

RocketMQ install

RocketMQ It's pure. Java、 Distributed 、 Open source message middleware of queue model , build RocketMQ Configuration required JAVA environment variable .

Download installation package

Go to the official website and select the required version to download the installation package ( The following 4.8.0 For example ). Official website download address : Download from the official website
Download the compiled binary file , You can also choose your own source file . It is mainly installed in the form of binary package .
The download is also shown in the figure below :
 Insert picture description here

install RocketMQ

1、 Unzip the installation package , Go to the installation directory bin Folder , This includes MQ The startup script , Include sh and cmd Script ;
2、 Modify virtual machine memory ,RocketMQ The default virtual machine has large memory , start-up Broker perhaps NameServer May fail due to insufficient memory , It needs to be modified according to the actual situation Broker and NameServer Virtual machine memory for . compile runbroker and runserver file (win Modify in environment cmd Script ,linux Modify in environment sh The script can be ), The following are the reference settings :

#  With linux In the environment, for example , edit  and  Change the default  JVM  size 
$ vi bin/
#  modify -server Parameters 
set "JAVA_OPT=%JAVA_OPT% -server -Xms2g -Xmx2g -Xmn1g"

$ vi bin/
#  modify -server Parameters 
set "JAVA_OPT=%JAVA_OPT% -server -Xms2g -Xmx2g -Xmn1g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"

 Insert picture description here

start-up RocketMQ

1、 start-up NameServer

# windows Start in environment 
# linux Start in environment 
sh mqnamesrv
#  Background start 
nohup sh mqnamesrv &

2、 start-up Broker

# windows Start in environment 
.\mqbroker -n 
# linux Start in environment 
sh mqbroker -n 
#  Background start 
nohup sh mqbroker -n localhost:9876 &

3、 close MQ service

# windows Start in environment 
.\mqshutdown namesrv // close NameServer
.\mqshutdown broker	 // close Broker
# linux Start in environment 
sh bin/mqshutdown namesrv // close NameServer
sh bin/mqshutdown broker // close Broker

window If you can't start broker, Delete c:/user/ user name /store Ask all questions and restart .

Build a visual monitoring platform

rocketmq-dashboard yes RocketMQ An expanded open source project , It can be done to MQ Visual monitoring .
Download address :
1、 Download the project and add the namesrv Change the address to your own NameServer Address ;
2、 Compile and package after configuration , Then start the packaged jar That's all right. ;
After successful startup, you can access... Through the browser http://ip Address : port Go to the console page , Visual query MQ Information about services , As shown in the figure below :
 Insert picture description here

For detailed use of the console, you can view :
thus RocketMQ Installation completed .

copyright notice
author[There are people on the mountain],Please bring the original link to reprint, thank you.

Random recommended