All Products
Document Center

How to use the Java SDK

Last Updated: Mar 29, 2019

RocketMQ provides the Java SDK for message delivery and subscription. This topic describes the parameters of Java interfaces and shows you how to use these interfaces.

Sample code for the transmission and reception of messages

Common parameters

Parameter Description
NAMESRV_ADDR The TCP endpoint, which is obtained from the console.
AccessKey The AccessKeyId you created in the Alibaba Cloud console for identity authentication.
SecretKey The AccessKeySecret you created in the Alibaba Cloud console for identity authentication.
OnsChannel The user channel, which is ALIYUN by default and CLOUD for Alibaba Retail Cloud users.

Message transmission parameters

Parameter Description
SendMsgTimeoutMillis The message transmission timeout period (in milliseconds). Default value: 3000
CheckImmunityTimeInSeconds (transactional messages) The shortest time interval (in seconds) before the first recheck of a transactional message.
shardingKey (ordered messages) The sharding key for ordered messages.


Message subscription parameters

Parameter Description
GROUP_ID The group ID you created in the console.
MessageModel The consumption mode of a consumer instance, which can be CLUSTERING (default) or BROADCASTING.
ConsumeThreadNums The number of consumption threads for a consumer instance. Default value: 20
MaxReconsumeTimes The maximum number of retries upon a consumption failure. Default value: 16
ConsumeTimeout The maximum consumption timeout period for each message. If a message fails to be processed within this period, the consumption fails, and the message needs to be resent for consumption. Set an appropriate value (in minutes) for each business application. Default value: 15.
suspendTimeMillis (ordered message) The retry interval for messages that fail to be consumed.