[GitHub] [rocketmq] qqeasonchen commented on a change in pull request #1422: [RIP-16]Support request/response pattern
qqeasonchen commented on a change in pull request #1422: [RIP-16]Support request/response pattern URL: https://github.com/apache/rocketmq/pull/1422#discussion_r344088310 ## File path: client/src/main/java/org/apache/rocketmq/client/impl/producer/DefaultMQProducerImpl.java ## @@ -1319,6 +1337,245 @@ public SendResult send(Message msg, return this.sendDefaultImpl(msg, CommunicationMode.SYNC, null, timeout); } +public Message request(Message msg, +long timeout) throws RequestTimeoutException, MQClientException, RemotingException, MQBrokerException, InterruptedException { +long beginTimestamp = System.currentTimeMillis(); +prepareSendRequest(msg, timeout); +final String requestUniqId = msg.getProperty(MessageConst.PROPERTY_REQUEST_UNIQ_ID); + +try { +final RequestResponseFuture requestResponseFuture = new RequestResponseFuture(requestUniqId, timeout, null); +RequestFutureTable.getRequestFutureTable().put(requestUniqId, requestResponseFuture); + +long cost = System.currentTimeMillis() - beginTimestamp; +this.sendDefaultImpl(msg, CommunicationMode.ASYNC, new SendCallback() { +@Override +public void onSuccess(SendResult sendResult) { +requestResponseFuture.setSendReqeustOk(true); +} + +@Override +public void onException(Throwable e) { +requestResponseFuture.setSendReqeustOk(false); +requestResponseFuture.putResponseMessage(null); +requestResponseFuture.setCause(e); +} +}, timeout - cost); + +Message responseMessage = requestResponseFuture.waitResponseMessage(timeout - cost); +if (responseMessage == null) { +if (requestResponseFuture.isSendRequestOk()) { +throw new RequestTimeoutException(ClientErrorCode.REQUEST_TIMEOUT_EXCEPTION, +"send request message to <" + msg.getTopic() + "> OK, but wait reply message timeout, " + timeout + " ms."); +} else { +throw new MQClientException("send request message to <" + msg.getTopic() + "> fail", requestResponseFuture.getCause()); +} +} +return responseMessage; +} finally { +RequestFutureTable.getRequestFutureTable().remove(requestUniqId); +} +} + +public void request(Message msg, final RequestCallback requestCallback, long timeout) throws RemotingException { +long beginTimestamp = System.currentTimeMillis(); +prepareSendRequest(msg, timeout); +final String requestUniqId = msg.getProperty(MessageConst.PROPERTY_REQUEST_UNIQ_ID); + +try { +final RequestResponseFuture requestResponseFuture = new RequestResponseFuture(requestUniqId, timeout, requestCallback); +RequestFutureTable.getRequestFutureTable().put(requestUniqId, requestResponseFuture); + +long cost = System.currentTimeMillis() - beginTimestamp; +this.sendDefaultImpl(msg, CommunicationMode.ASYNC, new SendCallback() { +@Override +public void onSuccess(SendResult sendResult) { +requestResponseFuture.setSendReqeustOk(true); +} + +@Override +public void onException(Throwable e) { +requestResponseFuture.setCause(e); +requestFail(requestUniqId); +} +}, timeout - cost); +} catch (Exception ex) { +log.warn("send request message to <{}> failed.", msg.getTopic(), ex); +throw new RemotingSendRequestException(msg.getTopic(), ex); +} +} + +public Message request(final Message msg, final MessageQueueSelector selector, final Object arg, +final long timeout) throws MQClientException, RemotingException, MQBrokerException, +InterruptedException, RequestTimeoutException { +long beginTimestamp = System.currentTimeMillis(); +prepareSendRequest(msg, timeout); +final String requestUniqId = msg.getProperty(MessageConst.PROPERTY_REQUEST_UNIQ_ID); + +try { +final RequestResponseFuture requestResponseFuture = new RequestResponseFuture(requestUniqId, timeout, null); +RequestFutureTable.getRequestFutureTable().put(requestUniqId, requestResponseFuture); + +long cost = System.currentTimeMillis() - beginTimestamp; +this.sendSelectImpl(msg, selector, arg, CommunicationMode.ASYNC, new SendCallback() { +@Override +public void onSuccess(SendResult sendResult) { +requestResponseFuture.setSendReqeustOk(true); +} + +@Override +public void
[GitHub] [rocketmq] qqeasonchen commented on a change in pull request #1422: [RIP-16]Support request/response pattern
qqeasonchen commented on a change in pull request #1422: [RIP-16]Support request/response pattern URL: https://github.com/apache/rocketmq/pull/1422#discussion_r33734 ## File path: client/src/main/java/org/apache/rocketmq/client/impl/ClientRemotingProcessor.java ## @@ -213,4 +221,79 @@ private RemotingCommand consumeMessageDirectly(ChannelHandlerContext ctx, return response; } + +private RemotingCommand receiveReplyMssage(ChannelHandlerContext ctx, +RemotingCommand request) throws RemotingCommandException { + +final RemotingCommand response = RemotingCommand.createResponseCommand(null); +long receiveTime = System.currentTimeMillis(); +ReplyMessageRequestHeader requestHeader = (ReplyMessageRequestHeader) request.decodeCommandCustomHeader(ReplyMessageRequestHeader.class); + +try { +MessageExt msg = new MessageExt(); +msg.setTopic(requestHeader.getTopic()); +msg.setQueueId(requestHeader.getQueueId()); +msg.setStoreTimestamp(requestHeader.getStoreTimestamp()); + +if (requestHeader.getBornHost() != null) { +String[] bornHostArr = requestHeader.getBornHost().split("/"); +String bornHost/*ip:port*/ = bornHostArr[bornHostArr.length - 1]; +String[] host = bornHost.split(":"); +if (host.length == 2) +msg.setBornHost(new InetSocketAddress(host[0], Integer.parseInt(host[1]))); +} + +if (requestHeader.getStoreHost() != null) { +String[] storeHostArr = requestHeader.getStoreHost().split("/"); +String storeHost = storeHostArr[storeHostArr.length - 1]; +String[] host = storeHost.split(":"); +if (host.length == 2) +msg.setStoreHost(new InetSocketAddress(host[0], Integer.parseInt(host[1]))); +} + +byte[] body = request.getBody(); +if ((requestHeader.getSysFlag() & MessageSysFlag.COMPRESSED_FLAG) == MessageSysFlag.COMPRESSED_FLAG) { +try { +body = UtilAll.uncompress(body); +} catch (IOException e) { +log.warn("err when uncompress constant", e); +} +} +msg.setBody(body); +msg.setFlag(requestHeader.getFlag()); +MessageAccessor.setProperties(msg, MessageDecoder.string2messageProperties(requestHeader.getProperties())); +MessageAccessor.putProperty(msg, MessageConst.PROPERTY_REPLY_MESSAGE_ARRIVE_TIME, String.valueOf(receiveTime)); +msg.setBornTimestamp(requestHeader.getBornTimestamp()); +msg.setReconsumeTimes(requestHeader.getReconsumeTimes() == null ? 0 : requestHeader.getReconsumeTimes()); +log.debug("receive reply message :{}", msg); + +processReplyMessage(msg); + +response.setCode(ResponseCode.SUCCESS); +response.setRemark(null); +} catch (Exception e) { +log.warn("unknown err when receiveReplyMsg", e); +response.setCode(ResponseCode.SYSTEM_ERROR); +response.setRemark("process reply message fail"); +} +return response; +} + +private void processReplyMessage(MessageExt replyMsg) { +final String correlationId = replyMsg.getUserProperty(MessageConst.PROPERTY_CORRELATION_ID); +final RequestResponseFuture requestResponseFuture = RequestFutureTable.getRequestFutureTable().get(correlationId); +if (requestResponseFuture != null) { +requestResponseFuture.putResponseMessage(replyMsg); + +RequestFutureTable.getRequestFutureTable().remove(correlationId); + +if (requestResponseFuture.getRequestCallback() != null) { +requestResponseFuture.getRequestCallback().onSuccess(replyMsg); +} else { +requestResponseFuture.putResponseMessage(replyMsg); +} +} else { +log.warn(String.format("receive reply message, but not matched any request, CorrelationId: %s", correlationId)); Review comment: In this implement, ReplyMessageProcessor will push reply message to producer and then store the reply message, so that it has low latency without waiting store message. So the reply message pushed to producer has no msgId. Would it be better that store reply message first and then push reply message to producer so that reply message can get a msgId ? 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: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [rocketmq] qqeasonchen commented on a change in pull request #1422: [RIP-16]Support request/response pattern
qqeasonchen commented on a change in pull request #1422: [RIP-16]Support request/response pattern URL: https://github.com/apache/rocketmq/pull/1422#discussion_r336818173 ## File path: client/src/main/java/org/apache/rocketmq/client/impl/ClientRemotingProcessor.java ## @@ -213,4 +221,79 @@ private RemotingCommand consumeMessageDirectly(ChannelHandlerContext ctx, return response; } + +private RemotingCommand receiveReplyMssage(ChannelHandlerContext ctx, +RemotingCommand request) throws RemotingCommandException { + +final RemotingCommand response = RemotingCommand.createResponseCommand(null); +long receiveTime = System.currentTimeMillis(); +ReplyMessageRequestHeader requestHeader = (ReplyMessageRequestHeader) request.decodeCommandCustomHeader(ReplyMessageRequestHeader.class); + +try { +MessageExt msg = new MessageExt(); +msg.setTopic(requestHeader.getTopic()); +msg.setQueueId(requestHeader.getQueueId()); +msg.setStoreTimestamp(requestHeader.getStoreTimestamp()); + +if (requestHeader.getBornHost() != null) { +String[] bornHostArr = requestHeader.getBornHost().split("/"); +String bornHost/*ip:port*/ = bornHostArr[bornHostArr.length - 1]; +String[] host = bornHost.split(":"); +if (host.length == 2) +msg.setBornHost(new InetSocketAddress(host[0], Integer.parseInt(host[1]))); +} + +if (requestHeader.getStoreHost() != null) { +String[] storeHostArr = requestHeader.getStoreHost().split("/"); +String storeHost = storeHostArr[storeHostArr.length - 1]; +String[] host = storeHost.split(":"); +if (host.length == 2) +msg.setStoreHost(new InetSocketAddress(host[0], Integer.parseInt(host[1]))); +} + +byte[] body = request.getBody(); +if ((requestHeader.getSysFlag() & MessageSysFlag.COMPRESSED_FLAG) == MessageSysFlag.COMPRESSED_FLAG) { +try { +body = UtilAll.uncompress(body); +} catch (IOException e) { +log.warn("err when uncompress constant", e); +} +} +msg.setBody(body); +msg.setFlag(requestHeader.getFlag()); +MessageAccessor.setProperties(msg, MessageDecoder.string2messageProperties(requestHeader.getProperties())); +MessageAccessor.putProperty(msg, MessageConst.PROPERTY_REPLY_MESSAGE_ARRIVE_TIME, String.valueOf(receiveTime)); +msg.setBornTimestamp(requestHeader.getBornTimestamp()); +msg.setReconsumeTimes(requestHeader.getReconsumeTimes() == null ? 0 : requestHeader.getReconsumeTimes()); +log.debug("receive reply message :{}", msg); + +processReplyMessage(msg); + +response.setCode(ResponseCode.SUCCESS); +response.setRemark(null); +} catch (Exception e) { +log.warn("unknown err when receiveReplyMsg", e); +response.setCode(ResponseCode.SYSTEM_ERROR); +response.setRemark("process reply message fail"); +} +return response; +} + +private void processReplyMessage(MessageExt replyMsg) { +final String correlationId = replyMsg.getUserProperty(MessageConst.PROPERTY_CORRELATION_ID); +final RequestResponseFuture requestResponseFuture = RequestFutureTable.getRequestFutureTable().get(correlationId); +if (requestResponseFuture != null) { +requestResponseFuture.putResponseMessage(replyMsg); + +RequestFutureTable.getRequestFutureTable().remove(correlationId); + +if (requestResponseFuture.getRequestCallback() != null) { +requestResponseFuture.getRequestCallback().onSuccess(replyMsg); +} else { +requestResponseFuture.putResponseMessage(replyMsg); +} +} else { +log.warn(String.format("receive reply message, but not matched any request, CorrelationId: %s", correlationId)); Review comment: Is the msgId of request message or reply message? 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: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [rocketmq] qqeasonchen commented on a change in pull request #1422: [RIP-16]Support request/response pattern
qqeasonchen commented on a change in pull request #1422: [RIP-16]Support request/response pattern URL: https://github.com/apache/rocketmq/pull/1422#discussion_r335265409 ## File path: client/src/main/java/org/apache/rocketmq/client/impl/producer/DefaultMQProducerImpl.java ## @@ -1319,6 +1337,245 @@ public SendResult send(Message msg, return this.sendDefaultImpl(msg, CommunicationMode.SYNC, null, timeout); } +public Message request(Message msg, +long timeout) throws RequestTimeoutException, MQClientException, RemotingException, MQBrokerException, InterruptedException { +long beginTimestamp = System.currentTimeMillis(); +prepareSendRequest(msg, timeout); +final String requestUniqId = msg.getProperty(MessageConst.PROPERTY_REQUEST_UNIQ_ID); + +try { +final RequestResponseFuture requestResponseFuture = new RequestResponseFuture(requestUniqId, timeout, null); +RequestFutureTable.getRequestFutureTable().put(requestUniqId, requestResponseFuture); + +long cost = System.currentTimeMillis() - beginTimestamp; +this.sendDefaultImpl(msg, CommunicationMode.ASYNC, new SendCallback() { +@Override +public void onSuccess(SendResult sendResult) { +requestResponseFuture.setSendReqeustOk(true); +} + +@Override +public void onException(Throwable e) { +requestResponseFuture.setSendReqeustOk(false); +requestResponseFuture.putResponseMessage(null); +requestResponseFuture.setCause(e); +} +}, timeout - cost); + +Message responseMessage = requestResponseFuture.waitResponseMessage(timeout - cost); +if (responseMessage == null) { +if (requestResponseFuture.isSendRequestOk()) { +throw new RequestTimeoutException(ClientErrorCode.REQUEST_TIMEOUT_EXCEPTION, +"send request message to <" + msg.getTopic() + "> OK, but wait reply message timeout, " + timeout + " ms."); +} else { +throw new MQClientException("send request message to <" + msg.getTopic() + "> fail", requestResponseFuture.getCause()); +} +} +return responseMessage; +} finally { +RequestFutureTable.getRequestFutureTable().remove(requestUniqId); +} +} + +public void request(Message msg, final RequestCallback requestCallback, long timeout) throws RemotingException { +long beginTimestamp = System.currentTimeMillis(); +prepareSendRequest(msg, timeout); +final String requestUniqId = msg.getProperty(MessageConst.PROPERTY_REQUEST_UNIQ_ID); + +try { +final RequestResponseFuture requestResponseFuture = new RequestResponseFuture(requestUniqId, timeout, requestCallback); +RequestFutureTable.getRequestFutureTable().put(requestUniqId, requestResponseFuture); + +long cost = System.currentTimeMillis() - beginTimestamp; +this.sendDefaultImpl(msg, CommunicationMode.ASYNC, new SendCallback() { +@Override +public void onSuccess(SendResult sendResult) { +requestResponseFuture.setSendReqeustOk(true); +} + +@Override +public void onException(Throwable e) { +requestResponseFuture.setCause(e); +requestFail(requestUniqId); +} +}, timeout - cost); +} catch (Exception ex) { +log.warn("send request message to <{}> failed.", msg.getTopic(), ex); +throw new RemotingSendRequestException(msg.getTopic(), ex); +} +} + +public Message request(final Message msg, final MessageQueueSelector selector, final Object arg, +final long timeout) throws MQClientException, RemotingException, MQBrokerException, +InterruptedException, RequestTimeoutException { +long beginTimestamp = System.currentTimeMillis(); +prepareSendRequest(msg, timeout); +final String requestUniqId = msg.getProperty(MessageConst.PROPERTY_REQUEST_UNIQ_ID); + +try { +final RequestResponseFuture requestResponseFuture = new RequestResponseFuture(requestUniqId, timeout, null); +RequestFutureTable.getRequestFutureTable().put(requestUniqId, requestResponseFuture); + +long cost = System.currentTimeMillis() - beginTimestamp; +this.sendSelectImpl(msg, selector, arg, CommunicationMode.ASYNC, new SendCallback() { +@Override +public void onSuccess(SendResult sendResult) { +requestResponseFuture.setSendReqeustOk(true); +} + +@Override +public void
[GitHub] [rocketmq] qqeasonchen commented on a change in pull request #1422: [RIP-16]Support request/response pattern
qqeasonchen commented on a change in pull request #1422: [RIP-16]Support request/response pattern URL: https://github.com/apache/rocketmq/pull/1422#discussion_r335265209 ## File path: client/src/main/java/org/apache/rocketmq/client/impl/producer/DefaultMQProducerImpl.java ## @@ -1319,6 +1337,245 @@ public SendResult send(Message msg, return this.sendDefaultImpl(msg, CommunicationMode.SYNC, null, timeout); } +public Message request(Message msg, +long timeout) throws RequestTimeoutException, MQClientException, RemotingException, MQBrokerException, InterruptedException { +long beginTimestamp = System.currentTimeMillis(); +prepareSendRequest(msg, timeout); +final String requestUniqId = msg.getProperty(MessageConst.PROPERTY_REQUEST_UNIQ_ID); + +try { +final RequestResponseFuture requestResponseFuture = new RequestResponseFuture(requestUniqId, timeout, null); +RequestFutureTable.getRequestFutureTable().put(requestUniqId, requestResponseFuture); + +long cost = System.currentTimeMillis() - beginTimestamp; +this.sendDefaultImpl(msg, CommunicationMode.ASYNC, new SendCallback() { +@Override +public void onSuccess(SendResult sendResult) { +requestResponseFuture.setSendReqeustOk(true); +} + +@Override +public void onException(Throwable e) { +requestResponseFuture.setSendReqeustOk(false); +requestResponseFuture.putResponseMessage(null); +requestResponseFuture.setCause(e); +} +}, timeout - cost); + +Message responseMessage = requestResponseFuture.waitResponseMessage(timeout - cost); +if (responseMessage == null) { +if (requestResponseFuture.isSendRequestOk()) { +throw new RequestTimeoutException(ClientErrorCode.REQUEST_TIMEOUT_EXCEPTION, +"send request message to <" + msg.getTopic() + "> OK, but wait reply message timeout, " + timeout + " ms."); +} else { +throw new MQClientException("send request message to <" + msg.getTopic() + "> fail", requestResponseFuture.getCause()); +} +} +return responseMessage; +} finally { +RequestFutureTable.getRequestFutureTable().remove(requestUniqId); +} +} + +public void request(Message msg, final RequestCallback requestCallback, long timeout) throws RemotingException { +long beginTimestamp = System.currentTimeMillis(); +prepareSendRequest(msg, timeout); +final String requestUniqId = msg.getProperty(MessageConst.PROPERTY_REQUEST_UNIQ_ID); + +try { +final RequestResponseFuture requestResponseFuture = new RequestResponseFuture(requestUniqId, timeout, requestCallback); +RequestFutureTable.getRequestFutureTable().put(requestUniqId, requestResponseFuture); + +long cost = System.currentTimeMillis() - beginTimestamp; +this.sendDefaultImpl(msg, CommunicationMode.ASYNC, new SendCallback() { +@Override +public void onSuccess(SendResult sendResult) { +requestResponseFuture.setSendReqeustOk(true); +} + +@Override +public void onException(Throwable e) { +requestResponseFuture.setCause(e); +requestFail(requestUniqId); +} +}, timeout - cost); +} catch (Exception ex) { +log.warn("send request message to <{}> failed.", msg.getTopic(), ex); +throw new RemotingSendRequestException(msg.getTopic(), ex); +} +} + +public Message request(final Message msg, final MessageQueueSelector selector, final Object arg, +final long timeout) throws MQClientException, RemotingException, MQBrokerException, +InterruptedException, RequestTimeoutException { +long beginTimestamp = System.currentTimeMillis(); +prepareSendRequest(msg, timeout); +final String requestUniqId = msg.getProperty(MessageConst.PROPERTY_REQUEST_UNIQ_ID); + +try { +final RequestResponseFuture requestResponseFuture = new RequestResponseFuture(requestUniqId, timeout, null); +RequestFutureTable.getRequestFutureTable().put(requestUniqId, requestResponseFuture); + +long cost = System.currentTimeMillis() - beginTimestamp; +this.sendSelectImpl(msg, selector, arg, CommunicationMode.ASYNC, new SendCallback() { +@Override +public void onSuccess(SendResult sendResult) { +requestResponseFuture.setSendReqeustOk(true); +} + +@Override +public void
[GitHub] [rocketmq] qqeasonchen commented on a change in pull request #1422: [RIP-16]Support request/response pattern
qqeasonchen commented on a change in pull request #1422: [RIP-16]Support request/response pattern URL: https://github.com/apache/rocketmq/pull/1422#discussion_r335265025 ## File path: client/src/main/java/org/apache/rocketmq/client/utils/MessageUtil.java ## @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.rocketmq.client.utils; + +import org.apache.rocketmq.client.exception.MQClientException; +import org.apache.rocketmq.common.MixAll; +import org.apache.rocketmq.common.message.Message; +import org.apache.rocketmq.common.message.MessageAccessor; +import org.apache.rocketmq.common.message.MessageConst; + +public class MessageUtil { +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); +MessageAccessor.putProperty(replyMessage, MessageConst.PROPERTY_MESSAGE_TYPE, MixAll.REPLY_MESSAGE_FLAG); +MessageAccessor.putProperty(replyMessage, MessageConst.PROPERTY_REQUEST_UNIQ_ID, requestUniqId); +MessageAccessor.putProperty(replyMessage, MessageConst.PROPERTY_MESSAGE_REPLY_TO, replyTo); +MessageAccessor.putProperty(replyMessage, MessageConst.PROPERTY_MESSAGE_TTL, ttl); + +return replyMessage; +} else { +throw new MQClientException(-1, "create reply message fail, requestMessage error, property[" + MessageConst.PROPERTY_CLUSTER + "] is null."); Review comment: ok, I'll define a new code in ClientErrorCode. 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: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [rocketmq] qqeasonchen commented on a change in pull request #1422: [RIP-16]Support request/response pattern
qqeasonchen commented on a change in pull request #1422: [RIP-16]Support request/response pattern URL: https://github.com/apache/rocketmq/pull/1422#discussion_r335255197 ## File path: client/src/main/java/org/apache/rocketmq/client/impl/producer/DefaultMQProducerImpl.java ## @@ -1319,6 +1337,245 @@ public SendResult send(Message msg, return this.sendDefaultImpl(msg, CommunicationMode.SYNC, null, timeout); } +public Message request(Message msg, +long timeout) throws RequestTimeoutException, MQClientException, RemotingException, MQBrokerException, InterruptedException { +long beginTimestamp = System.currentTimeMillis(); +prepareSendRequest(msg, timeout); +final String requestUniqId = msg.getProperty(MessageConst.PROPERTY_REQUEST_UNIQ_ID); + +try { +final RequestResponseFuture requestResponseFuture = new RequestResponseFuture(requestUniqId, timeout, null); +RequestFutureTable.getRequestFutureTable().put(requestUniqId, requestResponseFuture); + +long cost = System.currentTimeMillis() - beginTimestamp; +this.sendDefaultImpl(msg, CommunicationMode.ASYNC, new SendCallback() { +@Override +public void onSuccess(SendResult sendResult) { +requestResponseFuture.setSendReqeustOk(true); +} + +@Override +public void onException(Throwable e) { +requestResponseFuture.setSendReqeustOk(false); +requestResponseFuture.putResponseMessage(null); +requestResponseFuture.setCause(e); +} +}, timeout - cost); + +Message responseMessage = requestResponseFuture.waitResponseMessage(timeout - cost); +if (responseMessage == null) { +if (requestResponseFuture.isSendRequestOk()) { +throw new RequestTimeoutException(ClientErrorCode.REQUEST_TIMEOUT_EXCEPTION, +"send request message to <" + msg.getTopic() + "> OK, but wait reply message timeout, " + timeout + " ms."); +} else { +throw new MQClientException("send request message to <" + msg.getTopic() + "> fail", requestResponseFuture.getCause()); +} +} +return responseMessage; +} finally { +RequestFutureTable.getRequestFutureTable().remove(requestUniqId); +} +} + +public void request(Message msg, final RequestCallback requestCallback, long timeout) throws RemotingException { +long beginTimestamp = System.currentTimeMillis(); +prepareSendRequest(msg, timeout); +final String requestUniqId = msg.getProperty(MessageConst.PROPERTY_REQUEST_UNIQ_ID); + +try { +final RequestResponseFuture requestResponseFuture = new RequestResponseFuture(requestUniqId, timeout, requestCallback); +RequestFutureTable.getRequestFutureTable().put(requestUniqId, requestResponseFuture); + +long cost = System.currentTimeMillis() - beginTimestamp; +this.sendDefaultImpl(msg, CommunicationMode.ASYNC, new SendCallback() { +@Override +public void onSuccess(SendResult sendResult) { +requestResponseFuture.setSendReqeustOk(true); +} + +@Override +public void onException(Throwable e) { +requestResponseFuture.setCause(e); +requestFail(requestUniqId); +} +}, timeout - cost); +} catch (Exception ex) { +log.warn("send request message to <{}> failed.", msg.getTopic(), ex); +throw new RemotingSendRequestException(msg.getTopic(), ex); +} +} + +public Message request(final Message msg, final MessageQueueSelector selector, final Object arg, +final long timeout) throws MQClientException, RemotingException, MQBrokerException, +InterruptedException, RequestTimeoutException { +long beginTimestamp = System.currentTimeMillis(); +prepareSendRequest(msg, timeout); +final String requestUniqId = msg.getProperty(MessageConst.PROPERTY_REQUEST_UNIQ_ID); + +try { +final RequestResponseFuture requestResponseFuture = new RequestResponseFuture(requestUniqId, timeout, null); +RequestFutureTable.getRequestFutureTable().put(requestUniqId, requestResponseFuture); + +long cost = System.currentTimeMillis() - beginTimestamp; +this.sendSelectImpl(msg, selector, arg, CommunicationMode.ASYNC, new SendCallback() { +@Override +public void onSuccess(SendResult sendResult) { +requestResponseFuture.setSendReqeustOk(true); +} + +@Override +public void
[GitHub] [rocketmq] qqeasonchen commented on a change in pull request #1422: [RIP-16]Support request/response pattern
qqeasonchen commented on a change in pull request #1422: [RIP-16]Support request/response pattern URL: https://github.com/apache/rocketmq/pull/1422#discussion_r335252421 ## File path: client/src/main/java/org/apache/rocketmq/client/impl/producer/DefaultMQProducerImpl.java ## @@ -1319,6 +1337,245 @@ public SendResult send(Message msg, return this.sendDefaultImpl(msg, CommunicationMode.SYNC, null, timeout); } +public Message request(Message msg, +long timeout) throws RequestTimeoutException, MQClientException, RemotingException, MQBrokerException, InterruptedException { +long beginTimestamp = System.currentTimeMillis(); +prepareSendRequest(msg, timeout); +final String requestUniqId = msg.getProperty(MessageConst.PROPERTY_REQUEST_UNIQ_ID); + +try { +final RequestResponseFuture requestResponseFuture = new RequestResponseFuture(requestUniqId, timeout, null); +RequestFutureTable.getRequestFutureTable().put(requestUniqId, requestResponseFuture); + +long cost = System.currentTimeMillis() - beginTimestamp; +this.sendDefaultImpl(msg, CommunicationMode.ASYNC, new SendCallback() { +@Override +public void onSuccess(SendResult sendResult) { +requestResponseFuture.setSendReqeustOk(true); +} + +@Override +public void onException(Throwable e) { +requestResponseFuture.setSendReqeustOk(false); +requestResponseFuture.putResponseMessage(null); +requestResponseFuture.setCause(e); +} +}, timeout - cost); + +Message responseMessage = requestResponseFuture.waitResponseMessage(timeout - cost); +if (responseMessage == null) { +if (requestResponseFuture.isSendRequestOk()) { +throw new RequestTimeoutException(ClientErrorCode.REQUEST_TIMEOUT_EXCEPTION, +"send request message to <" + msg.getTopic() + "> OK, but wait reply message timeout, " + timeout + " ms."); +} else { +throw new MQClientException("send request message to <" + msg.getTopic() + "> fail", requestResponseFuture.getCause()); +} +} +return responseMessage; +} finally { +RequestFutureTable.getRequestFutureTable().remove(requestUniqId); +} +} + +public void request(Message msg, final RequestCallback requestCallback, long timeout) throws RemotingException { +long beginTimestamp = System.currentTimeMillis(); +prepareSendRequest(msg, timeout); +final String requestUniqId = msg.getProperty(MessageConst.PROPERTY_REQUEST_UNIQ_ID); + +try { +final RequestResponseFuture requestResponseFuture = new RequestResponseFuture(requestUniqId, timeout, requestCallback); +RequestFutureTable.getRequestFutureTable().put(requestUniqId, requestResponseFuture); + +long cost = System.currentTimeMillis() - beginTimestamp; +this.sendDefaultImpl(msg, CommunicationMode.ASYNC, new SendCallback() { +@Override +public void onSuccess(SendResult sendResult) { +requestResponseFuture.setSendReqeustOk(true); +} + +@Override +public void onException(Throwable e) { +requestResponseFuture.setCause(e); +requestFail(requestUniqId); +} +}, timeout - cost); +} catch (Exception ex) { +log.warn("send request message to <{}> failed.", msg.getTopic(), ex); +throw new RemotingSendRequestException(msg.getTopic(), ex); +} +} + +public Message request(final Message msg, final MessageQueueSelector selector, final Object arg, +final long timeout) throws MQClientException, RemotingException, MQBrokerException, +InterruptedException, RequestTimeoutException { +long beginTimestamp = System.currentTimeMillis(); +prepareSendRequest(msg, timeout); +final String requestUniqId = msg.getProperty(MessageConst.PROPERTY_REQUEST_UNIQ_ID); + +try { +final RequestResponseFuture requestResponseFuture = new RequestResponseFuture(requestUniqId, timeout, null); +RequestFutureTable.getRequestFutureTable().put(requestUniqId, requestResponseFuture); + +long cost = System.currentTimeMillis() - beginTimestamp; +this.sendSelectImpl(msg, selector, arg, CommunicationMode.ASYNC, new SendCallback() { +@Override +public void onSuccess(SendResult sendResult) { +requestResponseFuture.setSendReqeustOk(true); +} + +@Override +public void
[GitHub] [rocketmq] qqeasonchen commented on a change in pull request #1422: [RIP-16]Support request/response pattern
qqeasonchen commented on a change in pull request #1422: [RIP-16]Support request/response pattern URL: https://github.com/apache/rocketmq/pull/1422#discussion_r327081746 ## File path: example/src/main/java/org/apache/rocketmq/example/rpc/ResponseConsumer.java ## @@ -0,0 +1,83 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.rocketmq.example.rpc; + +import java.util.List; +import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; +import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext; +import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus; +import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently; +import org.apache.rocketmq.client.exception.MQBrokerException; +import org.apache.rocketmq.client.exception.MQClientException; +import org.apache.rocketmq.client.log.ClientLogger; +import org.apache.rocketmq.client.producer.SendResult; +import org.apache.rocketmq.client.utils.MessageUtil; +import org.apache.rocketmq.common.consumer.ConsumeFromWhere; +import org.apache.rocketmq.common.message.Message; +import org.apache.rocketmq.common.message.MessageConst; +import org.apache.rocketmq.common.message.MessageExt; +import org.apache.rocketmq.logging.InternalLogger; +import org.apache.rocketmq.remoting.exception.RemotingException; + +public class ResponseConsumer { +private static final InternalLogger log = ClientLogger.getLog(); + +public static void main(String[] args) throws InterruptedException, MQClientException { +String consumerGroup = "ConsumeGroup-Name"; +String namesrvAddr = "10.255.2.37:9873"; +String topic = "RequestTopic"; + +DefaultMQPushConsumer consumer = new DefaultMQPushConsumer(consumerGroup); +consumer.setNamesrvAddr(namesrvAddr); + consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_LAST_OFFSET); + +consumer.registerMessageListener(new MessageListenerConcurrently() { +@Override +public ConsumeConcurrentlyStatus consumeMessage(List msgs, ConsumeConcurrentlyContext context) { +System.out.printf("%s Receive New Messages: %s %n", Thread.currentThread().getName(), msgs); +for (MessageExt msg : msgs) { +try { +log.info("handle message: {} body={}", msg, new String(msg.getBody())); +String replyTo = msg.getProperty(MessageConst.PROPERTY_MESSAGE_REPLY_TO); + +//You must use MessageUtil to creage reply message, otherwise reply message maybe wrong. +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); Review comment: I add reply interface to consumer in the latest commit. I was thinking whether add the reply interface to producer or consumer, maybe adding to consumer is much easier to understand. 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: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [rocketmq] qqeasonchen commented on a change in pull request #1422: [RIP-16]Support request/response pattern
qqeasonchen commented on a change in pull request #1422: [RIP-16]Support request/response pattern URL: https://github.com/apache/rocketmq/pull/1422#discussion_r326949142 ## File path: client/src/main/java/org/apache/rocketmq/client/impl/ClientRemotingProcessor.java ## @@ -213,4 +221,78 @@ private RemotingCommand consumeMessageDirectly(ChannelHandlerContext ctx, return response; } + +private RemotingCommand receiveReplyMssage(ChannelHandlerContext ctx, +RemotingCommand request) throws RemotingCommandException { + +final RemotingCommand response = RemotingCommand.createResponseCommand(null); +long receiveTime = System.currentTimeMillis(); +ReplyMessageRequestHeader requestHeader = (ReplyMessageRequestHeader) request.decodeCommandCustomHeader(ReplyMessageRequestHeader.class); + +try { +MessageExt msg = new MessageExt(); +msg.setTopic(requestHeader.getTopic()); +msg.setQueueId(requestHeader.getQueueId()); +msg.setStoreTimestamp(requestHeader.getStoreTimestamp()); + +if (requestHeader.getBornHost() != null) { +String[] bornHostArr = requestHeader.getBornHost().split("/"); +String bornHost/*ip:port*/ = bornHostArr[bornHostArr.length - 1]; +String[] host = bornHost.split(":"); +if (host.length == 2) +msg.setBornHost(new InetSocketAddress(host[0], Integer.parseInt(host[1]))); +} + +if (requestHeader.getStoreHost() != null) { +String[] storeHostArr = requestHeader.getStoreHost().split("/"); +String storeHost = storeHostArr[storeHostArr.length - 1]; +String[] host = storeHost.split(":"); +if (host.length == 2) +msg.setStoreHost(new InetSocketAddress(host[0], Integer.parseInt(host[1]))); +} + +byte[] body = request.getBody(); +if ((requestHeader.getSysFlag() & MessageSysFlag.COMPRESSED_FLAG) == MessageSysFlag.COMPRESSED_FLAG) { +try { +body = UtilAll.uncompress(body); +} catch (IOException e) { +log.warn("err when uncompress constant", e); +} +} +msg.setBody(body); +msg.setFlag(requestHeader.getFlag()); +MessageAccessor.setProperties(msg, MessageDecoder.string2messageProperties(requestHeader.getProperties())); +MessageAccessor.putProperty(msg, MessageConst.PROPERTY_REPLY_MESSAGE_ARRIVE_TIME, String.valueOf(receiveTime)); +msg.setBornTimestamp(requestHeader.getBornTimestamp()); +msg.setReconsumeTimes(requestHeader.getReconsumeTimes() == null ? 0 : requestHeader.getReconsumeTimes()); +log.debug("receive reply message :{}", msg); + +processReplyMessage(msg); +} catch (Exception e) { +log.warn("unknown err when receiveRRReplyMsg", e); +response.setCode(ResponseCode.SYSTEM_ERROR); Review comment: Got it, i will correct it. 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: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [rocketmq] qqeasonchen commented on a change in pull request #1422: [RIP-16]Support request/response pattern
qqeasonchen commented on a change in pull request #1422: [RIP-16]Support request/response pattern URL: https://github.com/apache/rocketmq/pull/1422#discussion_r326942196 ## File path: client/src/main/java/org/apache/rocketmq/client/impl/producer/DefaultMQProducerImpl.java ## @@ -1310,6 +1332,247 @@ public SendResult send(Message msg, return this.sendDefaultImpl(msg, CommunicationMode.SYNC, null, timeout); } +public Message request(Message msg, +long timeout) throws RequestTimeoutException, MQClientException, RemotingException, MQBrokerException, InterruptedException { +prepareSendRequest(msg, timeout); +final String requestUniqId = msg.getProperty(MessageConst.PROPERTY_REQUEST_UNIQ_ID); + +try { +final RequestResponseFuture requestResponseFuture = new RequestResponseFuture(requestUniqId, timeout, null); +RequestFutureTable.getRequestFutureTable().put(requestUniqId, requestResponseFuture); + +this.sendDefaultImpl(msg, CommunicationMode.ASYNC, new SendCallback() { +@Override +public void onSuccess(SendResult sendResult) { +requestResponseFuture.setSendReqeustOk(true); +} + +@Override +public void onException(Throwable e) { +requestResponseFuture.setSendReqeustOk(false); +requestResponseFuture.putResponseMessage(null); +requestResponseFuture.setCause(e); +} +}, timeout); + +Message responseMessage = requestResponseFuture.waitResponseMessage(timeout); +if (responseMessage == null) { +if (requestResponseFuture.isSendReqeustOk()) { +throw new RequestTimeoutException(ClientErrorCode.REQUEST_TIMEOUT_EXCEPTION, +"send request message to <" + msg.getTopic() + "> OK, but wait reply message timeout, " + timeout + " ms."); +} else { +throw new MQClientException("send request message to <" + msg.getTopic() + "> fail", requestResponseFuture.getCause()); +} +} +return responseMessage; +} finally { +RequestFutureTable.getRequestFutureTable().remove(requestUniqId); +} +} + +public void request(Message msg, final RequestCallback requestCallback, long timeout) throws RemotingException { +prepareSendRequest(msg, timeout); +final String requestUniqId = msg.getProperty(MessageConst.PROPERTY_REQUEST_UNIQ_ID); + +try { +final RequestResponseFuture requestResponseFuture = new RequestResponseFuture(requestUniqId, timeout, requestCallback); +RequestFutureTable.getRequestFutureTable().put(requestUniqId, requestResponseFuture); + +this.sendDefaultImpl(msg, CommunicationMode.ASYNC, new SendCallback() { +@Override +public void onSuccess(SendResult sendResult) { +requestResponseFuture.setSendReqeustOk(true); +} + +@Override +public void onException(Throwable e) { +requestResponseFuture.setCause(e); +requestFail(requestUniqId); +} +}, timeout); +} catch (Exception ex) { +log.warn("send request message to <{}> failed.", msg.getTopic(), ex); +throw new RemotingSendRequestException(msg.getTopic(), ex); +} +} + +public Message request(final Message msg, final MessageQueueSelector selector, final Object arg, +final long timeout) throws MQClientException, RemotingException, MQBrokerException, +InterruptedException, RequestTimeoutException { +prepareSendRequest(msg, timeout); +final String requestUniqId = msg.getProperty(MessageConst.PROPERTY_REQUEST_UNIQ_ID); + +try { +final RequestResponseFuture requestResponseFuture = new RequestResponseFuture(requestUniqId, timeout, null); +RequestFutureTable.getRequestFutureTable().put(requestUniqId, requestResponseFuture); + +this.sendSelectImpl(msg, selector, arg, CommunicationMode.ASYNC, new SendCallback() { +@Override +public void onSuccess(SendResult sendResult) { +requestResponseFuture.setSendReqeustOk(true); +} + +@Override +public void onException(Throwable e) { +requestResponseFuture.setSendReqeustOk(false); +requestResponseFuture.putResponseMessage(null); +requestResponseFuture.setCause(e); +} +}, timeout); + +Message responseMessage = requestResponseFuture.waitResponseMessage(timeout); +if (responseMessage == null) { +
[GitHub] [rocketmq] qqeasonchen commented on a change in pull request #1422: [RIP-16]Support request/response pattern
qqeasonchen commented on a change in pull request #1422: [RIP-16]Support request/response pattern URL: https://github.com/apache/rocketmq/pull/1422#discussion_r326941121 ## File path: client/src/main/java/org/apache/rocketmq/client/producer/DefaultMQProducer.java ## @@ -582,6 +565,105 @@ public void send(Message msg, MessageQueueSelector selector, Object arg, SendCal this.defaultMQProducerImpl.send(msg, selector, arg, sendCallback, timeout); } +/** Review comment: Got it. 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: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [rocketmq] qqeasonchen commented on a change in pull request #1422: [RIP-16]Support request/response pattern
qqeasonchen commented on a change in pull request #1422: [RIP-16]Support request/response pattern URL: https://github.com/apache/rocketmq/pull/1422#discussion_r326936668 ## File path: client/src/main/java/org/apache/rocketmq/client/utils/MessageUtil.java ## @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.rocketmq.client.utils; + +import org.apache.rocketmq.client.exception.MQClientException; +import org.apache.rocketmq.common.MixAll; +import org.apache.rocketmq.common.message.Message; +import org.apache.rocketmq.common.message.MessageAccessor; +import org.apache.rocketmq.common.message.MessageConst; + +public class MessageUtil { +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); +MessageAccessor.putProperty(replyMessage, MessageConst.PROPERTY_MESSAGE_TYPE, MixAll.REPLY_MESSAGE_FLAG); +MessageAccessor.putProperty(replyMessage, MessageConst.PROPERTY_REQUEST_UNIQ_ID, requestUniqId); +MessageAccessor.putProperty(replyMessage, MessageConst.PROPERTY_MESSAGE_REPLY_TO, replyTo); +MessageAccessor.putProperty(replyMessage, MessageConst.PROPERTY_MESSAGE_TTL, ttl); + +return replyMessage; +} +} +throw new MQClientException(-1, "create reply message fail."); Review comment: We need some properties in the original request message, if request message is null or some properties is missing, we can not determinate where or who to send the reply message. I will make the message of exception more clear. 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: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [rocketmq] qqeasonchen commented on a change in pull request #1422: [RIP-16]Support request/response pattern
qqeasonchen commented on a change in pull request #1422: [RIP-16]Support request/response pattern URL: https://github.com/apache/rocketmq/pull/1422#discussion_r326935981 ## File path: example/src/main/java/org/apache/rocketmq/example/rpc/AsyncRequestProducer.java ## @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.rocketmq.example.rpc; + +import org.apache.rocketmq.client.exception.MQClientException; +import org.apache.rocketmq.client.log.ClientLogger; +import org.apache.rocketmq.client.producer.DefaultMQProducer; +import org.apache.rocketmq.client.producer.RequestCallback; +import org.apache.rocketmq.common.message.Message; +import org.apache.rocketmq.logging.InternalLogger; +import org.apache.rocketmq.remoting.common.RemotingHelper; + +public class AsyncRequestProducer { +private static final InternalLogger log = ClientLogger.getLog(); Review comment: I'll use System.out instead, like other example in the module. 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: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [rocketmq] qqeasonchen commented on a change in pull request #1422: [RIP-16]Support request/response pattern
qqeasonchen commented on a change in pull request #1422: [RIP-16]Support request/response pattern URL: https://github.com/apache/rocketmq/pull/1422#discussion_r326935537 ## File path: example/src/main/java/org/apache/rocketmq/example/rpc/RequestProducer.java ## @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.rocketmq.example.rpc; + +import org.apache.rocketmq.client.exception.MQClientException; +import org.apache.rocketmq.client.log.ClientLogger; +import org.apache.rocketmq.client.producer.DefaultMQProducer; +import org.apache.rocketmq.common.message.Message; +import org.apache.rocketmq.logging.InternalLogger; +import org.apache.rocketmq.remoting.common.RemotingHelper; + +public class RequestProducer { +private static final InternalLogger log = ClientLogger.getLog(); + +public static void main(String[] args) throws MQClientException, InterruptedException { +String producerGroup = "please_rename_unique_group_name"; +String topic = "RequestTopic"; +long ttl = 3000; + +DefaultMQProducer producer = new DefaultMQProducer(producerGroup); +producer.start(); + +try { +Message msg = new Message(topic, +"", +"Hello world".getBytes(RemotingHelper.DEFAULT_CHARSET)); + +long begin = System.currentTimeMillis(); +Message retMsg = producer.request(msg, ttl); +long cost = System.currentTimeMillis() - begin; +System.err.printf("request to <%s> cost: %d replyMessage: %s %n", topic, cost, retMsg); Review comment: yes, i'll correct it. 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: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [rocketmq] qqeasonchen commented on a change in pull request #1422: [RIP-16]Support request/response pattern
qqeasonchen commented on a change in pull request #1422: [RIP-16]Support request/response pattern URL: https://github.com/apache/rocketmq/pull/1422#discussion_r325462656 ## File path: example/src/main/java/org/apache/rocketmq/example/rpc/RequestProducer.java ## @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.rocketmq.example.rpc; + +import org.apache.rocketmq.client.exception.MQClientException; +import org.apache.rocketmq.client.log.ClientLogger; +import org.apache.rocketmq.client.producer.DefaultMQProducer; +import org.apache.rocketmq.common.message.Message; +import org.apache.rocketmq.logging.InternalLogger; +import org.apache.rocketmq.remoting.common.RemotingHelper; + +public class RequestProducer { +private static final InternalLogger log = ClientLogger.getLog(); + +public static void main(String[] args) throws MQClientException, InterruptedException { +String producerGroup = "ProducerGroup-Name"; +String namesrvAddr = "10.255.2.37:9876;10.255.2.37:9875"; Review comment: Ok. I'll optimize it and then re-commit it. Welcome any suggestion and feedback. 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: us...@infra.apache.org With regards, Apache Git Services