You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by GitBox <gi...@apache.org> on 2022/12/30 08:23:08 UTC

[GitHub] [rocketmq] xdkxlk commented on a diff in pull request #5788: Support long polling in rocketmq proxy in the protocol

xdkxlk commented on code in PR #5788:
URL: https://github.com/apache/rocketmq/pull/5788#discussion_r1059287625


##########
proxy/src/main/java/org/apache/rocketmq/proxy/grpc/v2/consumer/ReceiveMessageActivity.java:
##########
@@ -68,12 +68,23 @@ public void receiveMessage(ProxyContext ctx, ReceiveMessageRequest request,
             ProxyConfig config = ConfigurationManager.getProxyConfig();
 
             Long timeRemaining = ctx.getRemainingMs();
-            long pollTime = timeRemaining - Durations.toMillis(settings.getRequestTimeout()) / 2;
-            if (pollTime < 0) {
-                pollTime = 0;
+            long pollingTime;
+            if (request.hasLongPollingTimeout()) {
+                pollingTime = Durations.toMillis(request.getLongPollingTimeout());
+            } else {
+                pollingTime = timeRemaining - Durations.toMillis(settings.getRequestTimeout()) / 2;
+            }
+            if (pollingTime < config.getGrpcClientConsumerMinLongPollingTimeoutMillis()) {
+                pollingTime = config.getGrpcClientConsumerMinLongPollingTimeoutMillis();
+            }
+            if (pollingTime > config.getGrpcClientConsumerMaxLongPollingTimeoutMillis()) {
+                pollingTime = config.getGrpcClientConsumerMaxLongPollingTimeoutMillis();
             }
-            if (pollTime > config.getGrpcClientConsumerLongPollingTimeoutMillis()) {
-                pollTime = config.getGrpcClientConsumerLongPollingTimeoutMillis();
+
+            if (pollingTime > timeRemaining) {
+                writer.writeAndComplete(ctx, Code.ILLEGAL_POLLING_TIME, "The remaining time is not enough" +
+                    " for polling, please check await time or network");

Review Comment:
   Add timeRemaining in the error message is helpful for user to adjust parameters



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

To unsubscribe, e-mail: commits-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org