mirror of
https://github.com/apache/rocketmq.git
synced 2026-10-29 17:25:35 +08:00
Update RocketMQ_Example.md
This commit is contained in:
@@ -66,7 +66,11 @@ public class AsyncProducer {
|
||||
// 启动Producer实例
|
||||
producer.start();
|
||||
producer.setRetryTimesWhenSendAsyncFailed(0);
|
||||
for (int i = 0; i < 100; i++) {
|
||||
|
||||
int messageCount = 100;
|
||||
// 根据消息数量实例化倒计时计算器
|
||||
final CountDownLatch2 countDownLatch = new CountDownLatch2(messageCount);
|
||||
for (int i = 0; i < messageCount; i++) {
|
||||
final int index = i;
|
||||
// 创建消息,并指定Topic,Tag和消息体
|
||||
Message msg = new Message("TopicTest",
|
||||
@@ -87,6 +91,8 @@ public class AsyncProducer {
|
||||
}
|
||||
});
|
||||
}
|
||||
// 等待5s
|
||||
countDownLatch.await(5, TimeUnit.SECONDS);
|
||||
// 如果不再发送消息,关闭Producer实例。
|
||||
producer.shutdown();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user