RongtongJin commented on a change in pull request #209: [ISSUE #208]support 
request/reply model in rocketmq-spring
URL: https://github.com/apache/rocketmq-spring/pull/209#discussion_r363581165
 
 

 ##########
 File path: 
rocketmq-spring-boot-samples/rocketmq-produce-demo/src/main/java/org/apache/rocketmq/samples/springboot/ProducerApplication.java
 ##########
 @@ -116,6 +128,44 @@ public void onException(Throwable var1) {
 
         // Send transactional messages using extRocketMQTemplate
         testExtRocketMQTemplateTransaction();
+
+        // send request in sync mode and receive a reply of String type.
+        String replyString = 
rocketMQTemplate.sendAndReceive(stringRequestTopic, "request string", 
String.class);
+        System.out.printf("send %s and receive %s %n", "request string", 
replyString);
+
+        // send request in sync mode with timeout parameter and receive a 
reply of byte[] type.
+        byte[] replyBytes = rocketMQTemplate.sendAndReceive(bytesRequestTopic, 
new Message<String>() {
+            @Override public String getPayload() {
+                return "request byte[]";
+            }
+
+            @Override public MessageHeaders getHeaders() {
+                return null;
+            }
+        }, byte[].class, 3000);
+        System.out.printf("send %s and receive %s %n", "request byte[]", 
replyBytes.toString());
+
+        // send request in sync mode with hashKey parameter and receive a 
reply of User type.
+        User requestUser = new User().setUserAge(Byte.valueOf((byte) 
9)).setUserName("requestUserName");
+        User replyUser = rocketMQTemplate.sendAndReceive(objectRequestTopic, 
requestUser, User.class, "order-id");
+        System.out.printf("send %s and receive %s %n", requestUser, replyUser);
+        // send request in sync mode with timeout and delayLevel parameter 
parameter and receive a reply of generic type.
+        ProductWithPayload<String> replyGenericObject = 
rocketMQTemplate.sendAndReceive(genericRequestTopic, "request generic",
+            new TypeReference<ProductWithPayload<String>>() {
+            }.getType(), 30000, 2);
+        System.out.printf("send %s and receive %s %n", "request generic", 
replyGenericObject);
+
+        // send request in async mode and receive a reply of String type.
+        rocketMQTemplate.sendAndReceive(stringRequestTopic, "request string", 
new RequestCallback() {
+            @Override public void 
onSuccess(org.apache.rocketmq.common.message.Message message) {
+                System.out.print("receive reply content in callback: " + 
message.toString());
+            }
+
+            @Override public void onException(Throwable e) {
+                e.printStackTrace();
+            }
+        });
 
 Review comment:
   [Important] we need to switch RequestCallback, because rocketmq message 
expose to users.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to