1. 程式人生 > >rocketmq安裝與基本操作

rocketmq安裝與基本操作

tor ase mqtt lte wip struct .net air 參考

如果不是因為政治原因,就rocketmq的社區活躍度、版本、特性和文檔完善度,我是無論如何也不會使用rocketmq的。

rocketmq嚴格意義上並不支持高可靠性,因為其持久化只支持異步,有另外一個線程flush,不支持配置同步刷新到磁盤。只能說多個節點宕機的概率很低很低,外加現在的服務器一般都是UPS。

rocketmq官方提供了一份與activemq,kafka的特性對比(但沒有包括與rabbitmq的比較)。引用如下:

Messaging ProductClient SDKProtocol and SpecificationOrder MessageMessage FilterServer Triggered RedeliveryPersistent MessageRetroactive ConsumersMessage PriorityHigh Availability and FailoverMessage TrackConfigurationManagement and Operation Tools
ActiveMQ Java, .NET, C++ etc. Push model, support OpenWire, STOMP, AMQP, MQTT, JMS Exclusive Consumer or Exclusive Queues can ensure ordering Supported Not Supported Supports very fast persistence using JDBC along with a high performance journal,such as levelDB, kahaDB Supported Supported Supported, depending on storage,if using kahadb it requires a ZooKeeper server Not Supported The default configuration is low level, user need to optimize the configuration parameters Supported
Kafka Java, Scala etc. Pull model, support TCP Ensure ordering of messages within a partition Supported, you can use Kafka Streams to filter messages Not Supported High performance file storage Supported offset indicate Not Supported Supported, requires a ZooKeeper server Not Supported Kafka uses key-value pairs format for configuration. These values can be supplied either from a file or programmatically. Supported, use terminal command to expose core metrics
RocketMQ Java, .NET, C++ Pull model, support TCP, JMS Ensure strict ordering of messages, have no hot spot problem,and can scale out gracefully Supported, you can even upload yourself custom-built filter code snippets Supported High performance and low latency file storage Supported timestamp and offset 2 indicates Not Supported Supported, Master-Slave model, without another kit Supported Work out of box,user only need to pay attention to a few configurations Supported, rich web and terminal command to expose core metrics

rocketmq的整體架構如下:

技術分享

集群本身沒有什麽特殊之處,唯一的差別就是阿裏啥都喜歡搞分布式,加了註冊中心的概念(說白了就是抄襲zookeeper理念)。所以,要使用rocketmq,至少需要啟動兩個進程,nameserver、broker,前者是各種topic註冊中心,後者是真正的broker。

從apache rocketmq官方http://rocketmq.apache.org/release_notes/release-notes-4.0.0-incubating/現在最新版本二進制,當前是4.0.0孵化版。

下載解壓後得到apache-rocketmq-all。

在啟動前,如果測試服務器配置較低,則應該修改啟動命令runserver.sh(mqnamesrv裏面調用)和runbroker.sh(mqbroker裏面調用),將Xmx和Xms、Xmn值註釋或者降低,否則可能會在啟動時報內存分配失敗。

技術分享

技術分享

首先啟動nameserver。

nohup sh bin/mqnamesrv &
The Name Server boot success...
默認情況下,nameserver監聽的是9876端口。

其次啟動broker。

nohup sh bin/mqbroker -n localhost:9876 &
The broker[%s, 172.30.30.233:10911] boot success...
默認情況下,監聽的是10911端口。

安裝rocket web console。

默認情況下,rocketmq沒有提供二進制監控控制臺,需要自己build,可從github下載maven源碼builder。為方便,筆者打包了一份,https://pan.baidu.com/s/1jIp6Age。放到tomcat下啟動後,如下:

技術分享

下載後,只要更改WEB-INF\classes\config.properties中的rocketmq.namesrv.addr為nameserver地址即可。

停止的時候,順序相反,要先停止broker,其次停止nameserver。

sh bin/mqshutdown broker
The mqbroker(36695) is running...
Send shutdown request to mqbroker(36695) OK
sh bin/mqshutdown namesrv
The mqnamesrv(36664) is running...
Send shutdown request to mqnamesrv(36664) OK

同其他應用服務器應用一樣,rocketmq也提供了一些命令行工具用於不需要通過編程API可以管理mq服務器本身,主命令是mqadmin,支持的子命令包括:
The most commonly used mqadmin commands are:
   updateTopic          Update or create topic
   deleteTopic          Delete topic from broker and NameServer.
   updateSubGroup       Update or create subscription group
   deleteSubGroup       Delete subscription group from broker.
   updateBrokerConfig   Update broker‘s config
   updateTopicPerm      Update topic perm
   topicRoute           Examine topic route info
   topicStatus          Examine topic Status info
   topicClusterList     get cluster info for topic
   brokerStatus         Fetch broker runtime status data
   queryMsgById         Query Message by Id
   queryMsgByKey        Query Message by Key
   queryMsgByUniqueKey  Query Message by Unique key
   queryMsgByOffset     Query Message by offset
   queryMsgByUniqueKey  Query Message by Unique key
   printMsg             Print Message Detail
   sendMsgStatus        send msg to broker.
   brokerConsumeStats   Fetch broker consume stats data
   producerConnection   Query producer‘s socket connection and client version
   consumerConnection   Query consumer‘s socket connection, client version and subscription
   consumerProgress     Query consumers‘s progress, speed
   consumerStatus       Query consumer‘s internal data structure
   cloneGroupOffset     clone offset from other group.
   clusterList          List all of clusters
   topicList            Fetch all topic list from name server
   updateKvConfig       Create or update KV config.
   deleteKvConfig       Delete KV config.
   wipeWritePerm        Wipe write perm of broker in all name server
   resetOffsetByTime    Reset consumer offset by timestamp(without client restart).
   updateOrderConf      Create or update or delete order conf
   cleanExpiredCQ       Clean expired ConsumeQueue on broker.
   cleanUnusedTopic     Clean unused topic on broker.
   startMonitoring      Start Monitoring
   statsAll             Topic and Consumer tps stats
   syncDocs             Synchronize wiki and issue to github.com
   allocateMQ           Allocate MQ
   checkMsgSendRT       check message send response time
   clusterRT            List All clusters Message Send RT

See ‘mqadmin help <command>‘ for more information on a specific command.

更多文檔可參考:http://rocketmq.apache.org/docs/quick-start/

rocketmq集群安裝可參考https://my.oschina.net/tantexian/blog/698109。

rocketmq安裝與基本操作