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 a2d2712  Updated Home (markdown)
a2d2712 is described below

commit a2d271285ef5be1aee360033dddaca4ee8dd387b
Author: rongtong <[email protected]>
AuthorDate: Wed Dec 25 14:58:16 2019 +0800

    Updated Home (markdown)
---
 Home.md                                            |  1 -
 ...217\221\351\200\201\346\266\210\346\201\257.md" | 57 ++++++++++++++++++++++
 2 files changed, 57 insertions(+), 1 deletion(-)

diff --git a/Home.md b/Home.md
deleted file mode 100644
index 30d74d2..0000000
--- a/Home.md
+++ /dev/null
@@ -1 +0,0 @@
-test
\ No newline at end of file
diff --git "a/\345\217\221\351\200\201\346\266\210\346\201\257.md" 
"b/\345\217\221\351\200\201\346\266\210\346\201\257.md"
new file mode 100644
index 0000000..887ab30
--- /dev/null
+++ "b/\345\217\221\351\200\201\346\266\210\346\201\257.md"
@@ -0,0 +1,57 @@
+修改application.properties
+
+```properties
+## application.properties
+rocketmq.name-server=127.0.0.1:9876
+rocketmq.producer.group=my-group
+```
+
+> 注意:
+> 
+> 请将上述示例配置中的`127.0.0.1:9876`替换成真实RocketMQ的NameServer地址与端口
+
+编写代码
+
+```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;
+    }
+}
+```
\ No newline at end of file

Reply via email to