You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by du...@apache.org on 2022/06/06 02:53:56 UTC
[rocketmq] branch develop updated: [ISSUE #4323] Transaction example add the default NamesrvAddr (#4354)
This is an automated email from the ASF dual-hosted git repository.
duhengforever pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/rocketmq.git
The following commit(s) were added to refs/heads/develop by this push:
new 4fdf8b051 [ISSUE #4323] Transaction example add the default NamesrvAddr (#4354)
4fdf8b051 is described below
commit 4fdf8b0518a546b11d736761198b765e3ee69f94
Author: 李晓双 Li Xiao Shuang <64...@qq.com>
AuthorDate: Mon Jun 6 10:53:51 2022 +0800
[ISSUE #4323] Transaction example add the default NamesrvAddr (#4354)
* Transaction example add the default NamesrvAddr
* update annotation
---
.../example/transaction/TransactionProducer.java | 28 +++++++++++++---------
1 file changed, 17 insertions(+), 11 deletions(-)
diff --git a/example/src/main/java/org/apache/rocketmq/example/transaction/TransactionProducer.java b/example/src/main/java/org/apache/rocketmq/example/transaction/TransactionProducer.java
index 75c805b96..5973c3c30 100644
--- a/example/src/main/java/org/apache/rocketmq/example/transaction/TransactionProducer.java
+++ b/example/src/main/java/org/apache/rocketmq/example/transaction/TransactionProducer.java
@@ -26,21 +26,27 @@ import org.apache.rocketmq.remoting.common.RemotingHelper;
import java.io.UnsupportedEncodingException;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
-import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
public class TransactionProducer {
+
+ public static final String PRODUCER_GROUP = "please_rename_unique_group_name";
+ public static final String DEFAULT_NAMESRVADDR = "127.0.0.1:9876";
+ public static final String TOPIC = "TopicTest1234";
+
+ public static final int MESSAGE_COUNT = 10;
+
public static void main(String[] args) throws MQClientException, InterruptedException {
TransactionListener transactionListener = new TransactionListenerImpl();
- TransactionMQProducer producer = new TransactionMQProducer("please_rename_unique_group_name");
- ExecutorService executorService = new ThreadPoolExecutor(2, 5, 100, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(2000), new ThreadFactory() {
- @Override
- public Thread newThread(Runnable r) {
- Thread thread = new Thread(r);
- thread.setName("client-transaction-msg-check-thread");
- return thread;
- }
+ TransactionMQProducer producer = new TransactionMQProducer(PRODUCER_GROUP);
+
+ // Uncomment the following line while debugging, namesrvAddr should be set to your local address
+// producer.setNamesrvAddr(DEFAULT_NAMESRVADDR);
+ ExecutorService executorService = new ThreadPoolExecutor(2, 5, 100, TimeUnit.SECONDS, new ArrayBlockingQueue<>(2000), r -> {
+ Thread thread = new Thread(r);
+ thread.setName("client-transaction-msg-check-thread");
+ return thread;
});
producer.setExecutorService(executorService);
@@ -48,10 +54,10 @@ public class TransactionProducer {
producer.start();
String[] tags = new String[] {"TagA", "TagB", "TagC", "TagD", "TagE"};
- for (int i = 0; i < 10; i++) {
+ for (int i = 0; i < MESSAGE_COUNT; i++) {
try {
Message msg =
- new Message("TopicTest1234", tags[i % tags.length], "KEY" + i,
+ new Message(TOPIC, tags[i % tags.length], "KEY" + i,
("Hello RocketMQ " + i).getBytes(RemotingHelper.DEFAULT_CHARSET));
SendResult sendResult = producer.sendMessageInTransaction(msg, null);
System.out.printf("%s%n", sendResult);