edit-icon download-icon

Java SDK introduction

Last Updated: Oct 17, 2018

Message Queue (MQ) provides Java SDK to implement message delivery and message subscription. This topic will introduce the related parameters and usage instructions of the interfaces.

Sample Code for Sending and Receiving Messages

Common Parameters

Parameter Description
ONSAddr Set MQ TCP access point, fetched from the MQ console
NAMESRV_ADDR Set Name Server list (not recommended), alternative to ONSAddr
AccessKey The AccessKey you created on Alibaba Cloud Account Management Console for identity authentication
SecretKey The SecretKey you created on Alibaba Cloud Account Management Console for identity authentication
OnsChannel User channel, which is ALIYUN by default, and for Jushita users, it is CLOUD

Parameters for Sending Messages

Parameter Description
SendMsgTimeoutMillis Set the timeout period for message sending (ms), default: 3000
CheckImmunityTimeInSeconds (Transactional message) Set the shortest time for the first message status check of transactional messages (s)
shardingKey (Ordered message) Values used to calculate different shards in ordered messages


Parameters for Message Subscriptions

Parameter Description
ConsumerId The consumer ID you created on the MQ console
MessageModel Set the consumption mode for consumer instances, which is clustering consumption by default (value: CLUSTERING); broadcasting consumption (BROADCASTING)
ConsumeThreadNums Set the number of consumption threads for consumer instances. Default: 20
MaxReconsumeTimes Set the max number of retries after message consumption failure, default: 16
ConsumeTimeout Set the timeout period for message consumption. If the set time is exceeded, then message comsumption is considered as failed, and the message will be consumed upon next delivery. A proper value is required for each service (min). Default: 15
suspendTimeMillis (Ordered message) Set retry interval for message consumption failures, which is only applicable for ordered messages.


Thank you! We've received your feedback.