Client Configuration

Relative to RocketMQ's Broker cluster, producers and consumers are client. In this section, it mainly describes the common behavior configuration of producers and consumers. ​

1 Client Addressing mode

RocketMQ can let client find the Name Server, and then find the Brokerby the Name Server. Followings show a variety of configurations, and priority level from highly to lower, the highly priority configurations can override the lower priority configurations.

  • Specified Name Server address in the code, and multiple Name Server addresses are separated by semicolons
producer.setNamesrvAddr("192.168.0.1:9876;192.168.0.2:9876");  

consumer.setNamesrvAddr("192.168.0.1:9876;192.168.0.2:9876");
  • Specified Name Server address in the Java setup parameters
-Drocketmq.namesrv.addr=192.168.0.1:9876;192.168.0.2:9876  
  • Specified Name Server address in the envionment variables
export   NAMESRV_ADDR=192.168.0.1:9876;192.168.0.2:9876   
  • HTTP static server addressing(default)

After client started, it will access a http static server address, as: http://jmenv.tbsite.net:8080/rocketmq/nsaddr, this URL return the following contents:

192.168.0.1:9876;192.168.0.2:9876   

By default, the client accesses the HTTP server every 2 minutes, and update the local Name Server address.The URL is hardcoded in the code, you can change the target server by updating /etc/hosts file, such as add following configuration at the /etc/hosts:

10.232.22.67    jmenv.taobao.net   

HTTP static server addressing is recommended, because it is simple client deployment, and the Name Server cluster can be upgraded hot.

2 Client Configuration

DefaultMQProducer,TransactionMQProducer,DefaultMQPushConsumer,DefaultMQPullConsumer all extends the ClientConfig Class, ClientConfig as the client common configuration class. Client configuration style like getXXX,setXXX, each of the parameters can config by spring and also config their in the code. Such as the namesrvAddr parameter: producer.setNamesrvAddr("192.168.0.1:9876"), same with the other parameters.

2.1 Client Common Configuration

Pamater NameDefault ValueDescription
namesrvAddrName Server address list, multiple NameServer addresses are separated by semicolons
clientIPlocal IPClient local ip address, some machines will fail to recognize the client IP address, which needs to be enforced in the code
instanceNameDEFAULTName of the client instance, Multiple producers and consumers created by the client actually share one internal instance (this instance contains network connection, thread resources, etc.).
clientCallbackExecutorThreads4Number of communication layer asynchronous callback threads
pollNameServerInteval30000Polling the Name Server interval in milliseconds
heartbeatBrokerInterval30000The heartbeat interval, in milliseconds, is sent to the Broker
persistConsumerOffsetInterval5000The persistent Consumer consumes the progress interval in milliseconds

2.2 Producer Configuration

Pamater NameDefault ValueDescription
producerGroupDEFAULT_PRODUCERThe name of the Producer group. If multiple producers belong to one application and send the same message, they should be grouped into the same group
createTopicKeyTBW102When a message is sent, topics that do not exist on the server are automatically created and a Key is specified that can be used to configure the default route to the topic where the message is sent.
defaultTopicQueueNums4The number of default queue when sending messages and auto created topic which not exists the server
sendMsgTimeout10000Timeout time of sending message in milliseconds
compressMsgBodyOverHowmuch4096The message Body begins to compress beyond the size(the Consumer gets the message automatically unzipped.), unit of byte
retryAnotherBrokerWhenNotStoreOKFALSEIf send message and return sendResult but sendStatus!=SEND_OK, Whether to resend
retryTimesWhenSendFailed2If send message failed, maximum number of retries, this parameter only works for synchronous send mode
maxMessageSize4MBClient limit message size, over it may error. Server also limit so need to work with server
transactionCheckListenerThe transaction message looks back to the listener, if you want send transaction message, you must setup this
checkThreadPoolMinSize1Minimum of thread in thread pool when Broker look back Producer transaction status
checkThreadPoolMaxSize1Maximum of thread in thread pool when Broker look back Producer transaction status
checkRequestHoldMax2000Producer local buffer request queue size when Broker look back Producer transaction status
RPCHooknullThis parameter is passed in when the Producer is creating, including the pre-processing before the message sending and the processing after the message response. The user can do some security control or other operations in the first interface.

2.3 PushConsumer Configuration

Pamater NameDefault ValueDescription
consumerGroupDEFAULT_CONSUMERConsumer group name. If multi Consumer belong to an application, subscribe the same message and consume logic as the same, they should be gathered together
messageModelCLUSTERINGMessage support two mode: cluster consumption and broadcast consumption
consumeFromWhereCONSUME_FROM_LAST_OFFSETAfter Consumer started, default consumption from last location, it include two situation: One is last consumption location is not expired, and consumption start at last location; The other is last location expired, start consumption at current queue's first message
consumeTimestampHalf an hour agoOnly consumeFromWhere=CONSUME_FROM_TIMESTAMP, this can work
allocateMessageQueueStrategyAllocateMessageQueueAveragelyImplements strategy of Rebalance algorithms
subscriptionsubscription relation
messageListenermessage listener
offsetStoreConsumption progress store
consumeThreadMin10Minimum of thread in consumption thread pool
consumeThreadMax20Maximum of thread in consumption thread pool
consumeConcurrentlyMaxSpan2000Maximum span allowed for single queue parallel consumption
pullThresholdForQueue1000Pull message local queue cache maximum number of messages
pullInterval0Pull message interval, because long polling it is 0, but for flow control, you can set value which greater than 0 in milliseconds
consumeMessageBatchMaxSize1Batch consume message
pullBatchSize32Batch pull message

2.4 PullConsumer Configuration

Pamater NameDefault ValueDescription
consumerGroupDEFAULT_CONSUMERConsumer group name. If multi Consumer belong to an application, subscribe the same message and consume logic as the same, they should be gathered together
brokerSuspendMaxTimeMillis20000Long polling, Consumer pull message request suspended for the longest time in the Broker in milliseconds
consumerTimeoutMillisWhenSuspend30000Long polling, Consumer pull message request suspend in the Broker over this time value, client think timeout. Unit is milliseconds
consumerPullTimeoutMillis10000Not long polling, timeout time of pull message in milliseconds
messageModelBROADCASTINGMessage support two mode: cluster consumption and broadcast consumption
messageQueueListenerListening changing of queue
offsetStoreConsumption schedule store
registerTopicsCollection of registered topics
allocateMessageQueueStrategyAllocateMessageQueueAveragelyImplements strategy about Rebalance algorithm

2.5 Message Data Structure

Field NameDefault ValueDescription
TopicnullRequired, the name of the topic to which the message belongs
BodynullRequired, message body
TagsnullOptional, message tag, convenient for server filtering. Currently only one tag per message is supported
KeysnullOptional, represent this message's business keys, server create hash indexes based keys. After setting, you can find message by Topics,Keys in Console system. Because of hash indexes, please make key as unique as possible, such as order number, goods Id and so on.
Flag0Optional, it is entirely up to the application, and RocketMQ does not intervene
DelayTimeLevel0Optional, message delay level, 0 represent no delay, greater tan 0 can consume
WaitStoreMsgOKTRUEOptional, indicates whether the message is not answered until the server is down.