<!-- in your <dependencies> block --><dependency><groupId>org.apache.rocketmq</groupId><artifactId>rocketmq-client</artifactId><version>4.9.7</version></dependency><dependency><groupId>org.apache.rocketmq</groupId><artifactId>rocketmq-acl</artifactId><version>4.9.7</version></dependency>
// Instantiate the message producer.DefaultMQProducer producer = new DefaultMQProducer(groupName,new AclClientRPCHook(new SessionCredentials(accessKey, secretKey)) // ACL Permission);// Set the NameServer address. The address should be in the form of xxx.tencenttdmq.com:8080.producer.setNamesrvAddr(nameserver);// Start the Producer instance.producer.start();for (int i = 0; i < 10; i++) {// Create a message instance and establish the topic and content.Message msg = new Message(topic_name, ("Hello RocketMQ " + i).getBytes(RemotingHelper.DEFAULT_CHARSET));// Send the message.SendResult sendResult = producer.send(msg);System.out.printf("%s%n", sendResult);}
Parameter | Description |
accessKey | Role key, copied from the AccessKey column on the Cluster Permission page of the console. ![]() |
secretKey | Role name, copied from the SecretKey column on the Cluster Permission page of the console. |
nameserver | Get the cluster access address from the access information module on the console cluster basic information page. ![]() |
topic_name | Copy the Topic name from the Topic management page in the console. ![]() |
// Instantiate the consumerDefaultMQPushConsumer pushConsumer = new DefaultMQPushConsumer(groupName,new AclClientRPCHook(new SessionCredentials(accessKey, secretKey))); //ACL permissions// Set the NameServer address.pushConsumer.setNamesrvAddr(nameserver);// Subscribe to a topic.pushConsumer.subscribe(topic_name, "*");// Register a callback implementation class to process messages pulled from the broker.pushConsumer.registerMessageListener((MessageListenerConcurrently) (msgs, context) -> {// Message processing logic.System.out.printf("%s Receive New Messages: %s %n", Thread.currentThread().getName(), msgs);// Mark the message as being successfully consumed, and return to the processing status based on the consumption condition.return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;});// Start the consumer instance.pushConsumer.start();
Parameter | Description |
accessKey | Role key, copied from the AccessKey column on the Cluster Permission page of the console. ![]() |
secretKey | Role name, copied from the SecretKey column on the Cluster Permission page of the console. |
nameserver | Get the cluster access address from the access information module on the console cluster basic information page. ![]() |
groupName | Copy the consumer group name from the Group Management page in the console. ![]() |
topic_name | Copy the Topic name from the Topic management page in the console. ![]() |

Feedback