Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE #9196] Broker return pop stats when receive notification #9197

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,11 @@ public RemotingCommand processRequest(final ChannelHandlerContext ctx,
}

if (!hasMsg) {
if (popLongPollingService.polling(ctx, request, new PollingHeader(requestHeader)) == PollingResult.POLLING_SUC) {
PollingResult pollingResult = popLongPollingService.polling(ctx, request, new PollingHeader(requestHeader));
if (pollingResult == PollingResult.POLLING_SUC) {
return null;
} else if (pollingResult == PollingResult.POLLING_FULL) {
responseHeader.setPollingFull(true);
}
}
response.setCode(ResponseCode.SUCCESS);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* 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.consumer;

public class NotifyResult {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里我倒是建议用 Pair 去写,减少不必要的对象和阅读的复杂性

private boolean hasMsg;
private boolean pollingFull;

public boolean isHasMsg() {
return hasMsg;
}

public boolean isPollingFull() {
return pollingFull;
}

public void setHasMsg(boolean hasMsg) {
this.hasMsg = hasMsg;
}

public void setPollingFull(boolean pollingFull) {
this.pollingFull = pollingFull;
}

@Override public String toString() {
return "NotifyResult{" +
"hasMsg=" + hasMsg +
", pollingFull=" + pollingFull +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.rocketmq.client.ClientConfig;
import org.apache.rocketmq.client.consumer.AckCallback;
import org.apache.rocketmq.client.consumer.AckResult;
import org.apache.rocketmq.client.consumer.NotifyResult;
import org.apache.rocketmq.client.consumer.PopCallback;
import org.apache.rocketmq.client.consumer.PopResult;
import org.apache.rocketmq.client.consumer.PullCallback;
Expand Down Expand Up @@ -608,14 +609,23 @@ public CompletableFuture<Void> unlockBatchMQOneway(String brokerAddr,
}

public CompletableFuture<Boolean> notification(String brokerAddr, NotificationRequestHeader requestHeader,
long timeoutMillis) {
return notificationWithPollingStats(brokerAddr, requestHeader, timeoutMillis).thenApply(NotifyResult::isHasMsg);
}

public CompletableFuture<NotifyResult> notificationWithPollingStats(String brokerAddr,
NotificationRequestHeader requestHeader,
long timeoutMillis) {
RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.NOTIFICATION, requestHeader);
return this.getRemotingClient().invoke(brokerAddr, request, timeoutMillis).thenCompose(response -> {
CompletableFuture<Boolean> future0 = new CompletableFuture<>();
CompletableFuture<NotifyResult> future0 = new CompletableFuture<>();
if (response.getCode() == ResponseCode.SUCCESS) {
try {
NotificationResponseHeader responseHeader = (NotificationResponseHeader) response.decodeCommandCustomHeader(NotificationResponseHeader.class);
future0.complete(responseHeader.isHasMsg());
NotifyResult notifyResult = new NotifyResult();
notifyResult.setHasMsg(responseHeader.isHasMsg());
notifyResult.setPollingFull(responseHeader.isPollingFull());
future0.complete(notifyResult);
} catch (Throwable t) {
future0.completeExceptionally(t);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,20 @@ public class NotificationResponseHeader implements CommandCustomHeader {
@CFNotNull
private boolean hasMsg = false;

private boolean pollingFull = false;

public boolean isHasMsg() {
return hasMsg;
}

public boolean isPollingFull() {
return pollingFull;
}

public void setPollingFull(boolean pollingFull) {
this.pollingFull = pollingFull;
}

public void setHasMsg(boolean hasMsg) {
this.hasMsg = hasMsg;
}
Expand Down
Loading