rocketmq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jinrongt...@apache.org
Subject [rocketmq-spring.wiki] branch master updated: Created Send Message (markdown)
Date Wed, 25 Dec 2019 08:06:16 GMT
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 c28dc9e  Created Send Message (markdown)
c28dc9e is described below

commit c28dc9e7fbe2363eed0e35bda70f34673cf911e0
Author: rongtong <jinrongtong5@163.com>
AuthorDate: Wed Dec 25 16:06:10 2019 +0800

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

diff --git a/Send-Message.md b/Send-Message.md
new file mode 100644
index 0000000..4ea5372
--- /dev/null
+++ b/Send-Message.md
@@ -0,0 +1,65 @@
+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
+
+```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 {
+        //send message synchronously
+        rocketMQTemplate.convertAndSend("test-topic-1", "Hello, World!");
+      	//send spring message
+        rocketMQTemplate.send("test-topic-1", MessageBuilder.withPayload("Hello, World! I'm
from spring message").build());
+        //send messgae asynchronously
+      	rocketMQTemplate.asyncSend("test-topic-2", new OrderPaidEvent("T_001", new BigDecimal("88.00")),
new SendCallback() {
+            @Override
+            public void onSuccess(SendResult var1) {
+                System.out.printf("async onSucess SendResult=%s %n", var1);
+            }
+
+            @Override
+            public void onException(Throwable var1) {
+                System.out.printf("async onException Throwable=%s %n", var1);
+            }
+
+        });
+      	//Send messages orderly
+      	rocketMQTemplate.syncSendOrderly("orderly_topic",MessageBuilder.withPayload("Hello,
World").build(),"hashkey")
+        
+        //rocketMQTemplate.destroy(); // notes:  once rocketMQTemplate be destroyed, you
can not send any message again with this rocketMQTemplate
+    }
+    
+    @Data
+    @AllArgsConstructor
+    public class OrderPaidEvent implements Serializable{
+        private String orderId;
+        
+        private BigDecimal paidMoney;
+    }
+}
+```
+
+> More relevant configurations for producing:
+>
+> ```properties
+> rocketmq.producer.send-message-timeout=3000
+> rocketmq.producer.compress-message-body-threshold=4096
+> rocketmq.producer.max-message-size=4194304
+> rocketmq.producer.retry-times-when-send-async-failed=0
+> rocketmq.producer.retry-next-server=true
+> rocketmq.producer.retry-times-when-send-failed=2
+> ```
\ No newline at end of file


Mime
View raw message