[Distributed Learning] rocketmq message queue of notes

Documents Address

RocketMQ architecture

Beep beep miles miles on video

There are many mq, recently bought a "distributed messaging middleware practice," this book, learn the relevant knowledge of mq. mq roughly has four functions:

  1. Asynchronous processing. Such as business end user needs to send a message, and so does not need to be finished after sending the calling code before allowing the business end of the return.
  2. Service decoupling. Death does not need to call between service calls write certain services on the code, you only need to send a message. This message transmission process are generally returns immediately. Similar to generate a background job.
  3. Traffic clipping. Business system in a short period of time to do the activities of traffic will be particularly large, based on the characteristics of mq queue, you can deal with the problem of excessive instantaneous flow and reduce back-end pressure.
  4. Message traffic. The main subscription mechanism is similar to a chat room.

Introduction

Low latency distributed message processing platform, high performance, scalable, one trillion. It consists of four sections. name server, broker (news agents), producer, consumers. These four levels can be extended (made of clusters of way) to avoid a single point of failure.

NameServers (clusters)

NameServer is a fully functional service. Mainly includes the following two aspects:

  • Broker management. Broker registration messages received over the cluster, and then provide heartbeat mechanism to check whether Broker still alive.
  • Routing management. Each NameServer contains complete information about the routing of the Broker, and the query request processing queue of the client.

There are four ways for the client to specify the address NameServer.

  1. Programmatically. similarproducer.setNamesrvAddr("ip:port")
  2. Java configuration. userocketmq.namesrv.addr
  3. Environment variables. useNAMESRV_ADDR
  4. http endpoint.

Provide lightweight service discovery and routing, each Name Server records complete routing information, provide the appropriate service to read and write, while supporting the rapid storage expansion.

Broker (Cluster)

Broker responsible for message storage and distribution of news queries, high-availability assurance. Block as shown in FIG.

Broker module

So, he has several more important sub-modules:

  • Remote module. Broker an inlet for receiving a request over the client.
  • Client Management. For (producer / consumer) model of client management, maintenance of consumers subscribe to topics.
  • Storage services. Provide some simple api for queries or stored messages on the physical disk.
  • Ensure service availability. Providing data from the primary synchronization characteristic between Broker.
  • Indexing Service. Indexing the message through a specific key, and then provide information queries.

By topic queue mechanism to provide lightweight responsible for storing messages. Support zoom mode, comprising fault tolerance mechanisms (2 or 3 copies). The order of processing the message. Provide disaster response, early warning mechanism.

Producer (clusters)

Producers provide distributed deployment. Distributed by Broker sends a message to the producer of load balancing. Support rapid error feedback, and low latency.

Consumer (clusters)

Consumers also supports distributed deployment in push / pull mode. Support cluster consumption + message broadcast. Provide real-time news subscription mechanisms to meet most needs.

How to run (stand-alone test environment)

download

Like the installation package (also the source line), then extract

wget http://mirrors.tuna.tsinghua.edu.cn/apache/rocketmq/4.5.1/rocketmq-all-4.5.1-bin-release.zip
unzip rocketmq-all-4.5.1-bin-release.zip -d /usr/lib/rocketmq/

Some configuration change

Environment Variables

#配置64位jdk是必须的---这里跳过
export ROCKETMQ_HOME=/usr/lib/rocketmq/rocketmq #这个不是必须,只是方便下面操作
source ~/.bash_profile #使配置生效一下
rm -f ~/logs/rocketmqlogs/*.log # 把日志清了,方便查看

Startup Parameters

rocketmq default memory configuration requirements are too high for our test server requirements, and change a little lower.

vim $ROCKETMQ_HOME/bin/runserver.sh
# 把第39行改成
JAVA_OPT="${JAVA_OPT} -server -Xms1g -Xmx1g -Xmn1g" #最小,启动,最大都是1g

vim $ROCKETMQ_HOME/bin/runbroker.sh
# 把39行改成
JAVA_OPT="${JAVA_OPT} -server -Xms1g -Xmx1g -Xmn1g" # 同上面

broker configuration

vim $ROCKETMQ_HOME/conf/broker.conf
# 加这些配置
brokerIP1 = 192.168.3.20 #此broker的ip
namesvrAddr=192.168.3.20:9876 #nameServer地址,集群的话需要分号分隔。

Start NameServer

NameServer because of the need to manage the Broker, so the first start NameServer. The default log address ~/logs/rocketmqlogs.

nohup sh $ROCKETMQ_HOME/bin/mqnamesrv & # 以忽略挂起信号的方式启动nameserver
tail -f ~/logs/rocketmqlogs/namesrv.log # 监控的方式查看日志尾部

Start Broker

Messages to be distributed through a Broker, NameServer has started, it can now start the Broker.

nohup sh $ROCKETMQ_HOME/bin/mqbroker -c $ROCKETMQ_HOME/conf/broker.conf &
tail -f ~/logs/rocketmqlogs/broker.log

View web site

Here need to download this , there are a rocketmq-console. You need to modify one place. rocketmq-externals/rocketmq-console/src/main/resources/application.properties,

rocketmq.config.namesrvAddr=192.168.3.20:9876 #改成对应的namesrvAddr 地址

The server needs to open several ports for connecting the console, if not configured, the default is: 9876,10911,10909

firewall-cmd --zone=public --add-port=9876/tcp --permanent
firewall-cmd --reload

Then you can see the.

Console

Sending, receiving a message

Follow be practiced by way of the client code.

Close Service

sh $ROCKETMQ_HOME/bin/mqshutdown broker #先关了Broker
sh $ROCKETMQ_HOME/bin/mqshutdown namesrv #再关闭nameserver

Guess you like

Origin www.cnblogs.com/sheldon-lou/p/10966575.html
Recommended