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_r364545200
 
 

 ##########
 File path: 
rocketmq-spring-boot-samples/rocketmq-produce-demo/src/main/java/org/apache/rocketmq/samples/springboot/ProducerApplication.java
 ##########
 @@ -116,6 +128,53 @@ 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) 
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 RocketMQLocalRequestCallback<String>() {
+            @Override public void onSuccess(String message) {
+                System.out.println("receive string: " + message);
+            }
+
+            @Override public void onException(Throwable e) {
+                e.printStackTrace();
+            }
+        });
+        // send request in async mode and receive a reply of User type.
+        rocketMQTemplate.sendAndReceive(objectRequestTopic, new 
User().setUserAge((byte) 9).setUserName("requestUserName"), new 
RocketMQLocalRequestCallback<User>() {
+            @Override public void onSuccess(User message) {
+                System.out.println("receive User: " + message.toString());
+            }
+
+            @Override public void onException(Throwable e) {
+                e.printStackTrace();
+            }
+        }, 5000);
 
 Review comment:
   It would be better to use `System.out.printf` instead of `System.out.println`

----------------------------------------------------------------
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