diff --git a/client/src/main/java/org/apache/rocketmq/client/utils/MessageUtil.java b/client/src/main/java/org/apache/rocketmq/client/utils/MessageUtil.java index 81da669ff8a2913f0c302905e6e15405d5409198..e60c0f665f6d35a60b1098cdc56357ebb5f50e8c 100644 --- a/client/src/main/java/org/apache/rocketmq/client/utils/MessageUtil.java +++ b/client/src/main/java/org/apache/rocketmq/client/utils/MessageUtil.java @@ -24,13 +24,14 @@ import org.apache.rocketmq.common.message.MessageAccessor; import org.apache.rocketmq.common.message.MessageConst; public class MessageUtil { - public static Message createReplyMessage(final Message requestMessage) throws MQClientException { + public static Message createReplyMessage(final Message requestMessage, final byte[] body) throws MQClientException { if (requestMessage != null) { Message replyMessage = new Message(); String cluster = requestMessage.getProperty(MessageConst.PROPERTY_CLUSTER); String replyTo = requestMessage.getProperty(MessageConst.PROPERTY_MESSAGE_REPLY_TO); String requestUniqId = requestMessage.getProperty(MessageConst.PROPERTY_REQUEST_UNIQ_ID); String ttl = requestMessage.getProperty(MessageConst.PROPERTY_MESSAGE_TTL); + replyMessage.setBody(body); if (cluster != null) { String replyTopic = MixAll.getReplyTopic(cluster); replyMessage.setTopic(replyTopic); diff --git a/example/src/main/java/org/apache/rocketmq/example/rpc/ResponseConsumer.java b/example/src/main/java/org/apache/rocketmq/example/rpc/ResponseConsumer.java index ff3652fe3ad4196002cc723b6182ac2b313870cf..3580f87fb58a0f66824fc47b29ef61d3015e0261 100644 --- a/example/src/main/java/org/apache/rocketmq/example/rpc/ResponseConsumer.java +++ b/example/src/main/java/org/apache/rocketmq/example/rpc/ResponseConsumer.java @@ -56,8 +56,8 @@ public class ResponseConsumer { String replyTo = msg.getProperty(MessageConst.PROPERTY_MESSAGE_REPLY_TO); //You must use MessageUtil to creage reply message, otherwise reply message maybe wrong. - Message replyMessage = MessageUtil.createReplyMessage(msg); - replyMessage.setBody("reply message contents.".getBytes()); + byte[] replyContent = "reply message contents.".getBytes(); + Message replyMessage = MessageUtil.createReplyMessage(msg, replyContent); //maybe you should create a producer to send reply message. SendResult sendResult = consumer.getDefaultMQPushConsumerImpl().getmQClientFactory().getDefaultMQProducer().send(replyMessage, 3000);