fll666888 commented on issue #4339:
URL: https://github.com/apache/rocketmq/issues/4339#issuecomment-1132359512

   > @fll666888 u can refer following code
   > 
   > ```java
   >         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;
   >             }
   >         });
   > 
   >         producer.setExecutorService(executorService);
   >         producer.setTransactionListener(transactionListener);
   >         producer.start();
   > 
   >         String[] tags = new String[] {"TagA", "TagB", "TagC", "TagD", 
"TagE"};
   >         for (int i = 0; i < 10; i++) {
   >             try {
   >                 Message msg =
   >                     new Message("TopicTest1234", 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);
   > 
   >                 Thread.sleep(10);
   >             } catch (MQClientException | UnsupportedEncodingException e) {
   >                 e.printStackTrace();
   >             }
   >         }
   > ```
   
   之前就试过了,我的demo已经上传了,你可以试一下


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to