This is an automated email from the ASF dual-hosted git repository.

jinrongtong pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-spring.wiki.git


The following commit(s) were added to refs/heads/master by this push:
     new 31fb872  Created Send transactional Message (markdown)
31fb872 is described below

commit 31fb87258cf3687a38a161992d15015ce1a1f0ef
Author: rongtong <[email protected]>
AuthorDate: Wed Dec 25 16:08:38 2019 +0800

    Created Send transactional Message (markdown)
---
 Send-transactional-Message.md | 52 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)

diff --git a/Send-transactional-Message.md b/Send-transactional-Message.md
new file mode 100644
index 0000000..c8af03e
--- /dev/null
+++ b/Send-transactional-Message.md
@@ -0,0 +1,52 @@
+Modify application.properties
+```properties
+## application.properties
+rocketmq.name-server=127.0.0.1:9876
+rocketmq.producer.group=my-group
+```
+
+> Note:
+> 
+> Maybe you need change `127.0.0.1:9876` with your real NameServer address for 
RocketMQ
+
+Send message in transaction and implement local check Listener
+
+~~~java
+@SpringBootApplication
+public class ProducerApplication implements CommandLineRunner{
+    @Resource
+    private RocketMQTemplate rocketMQTemplate;
+
+    public static void main(String[] args){
+        SpringApplication.run(ProducerApplication.class, args);
+    }
+
+    public void run(String... args) throws Exception {
+        try {
+            // Build a SpringMessage for sending in transaction
+            Message msg = MessageBuilder.withPayload(..)...;
+            // In sendMessageInTransaction(), the first parameter transaction 
name ("test")
+            // must be same with the @RocketMQTransactionListener's member 
field 'transName'
+            rocketMQTemplate.sendMessageInTransaction("test", "test-topic", 
msg, null);
+        } catch (MQClientException e) {
+            e.printStackTrace(System.out);
+        }
+    }
+
+    // Define transaction listener with the annotation 
@RocketMQTransactionListener
+    @RocketMQTransactionListener
+    class TransactionListenerImpl implements RocketMQLocalTransactionListener {
+          @Override
+          public RocketMQLocalTransactionState executeLocalTransaction(Message 
msg, Object arg) {
+            // ... local transaction process, return bollback, commit or 
unknown
+            return RocketMQLocalTransactionState.UNKNOWN;
+          }
+
+          @Override
+          public RocketMQLocalTransactionState checkLocalTransaction(Message 
msg) {
+            // ... check transaction status and return bollback, commit or 
unknown
+            return RocketMQLocalTransactionState.COMMIT;
+          }
+    }
+}
+~~~
\ No newline at end of file

Reply via email to