From ac40f8e9639bd8c6946ec6e683e615e150a9a457 Mon Sep 17 00:00:00 2001 From: twei43846-afk <306386671+twei43846-afk@users.noreply.github.com> Date: Sat, 1 Aug 2026 21:54:23 +0800 Subject: [PATCH] [ISSUE #10671] Improve unsupported client type diagnostics --- .../proxy/grpc/v2/client/ClientActivity.java | 14 ++++++-- .../grpc/v2/client/ClientActivityTest.java | 34 +++++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/proxy/src/main/java/org/apache/rocketmq/proxy/grpc/v2/client/ClientActivity.java b/proxy/src/main/java/org/apache/rocketmq/proxy/grpc/v2/client/ClientActivity.java index abc23a53a3e..3d18e4a3da1 100644 --- a/proxy/src/main/java/org/apache/rocketmq/proxy/grpc/v2/client/ClientActivity.java +++ b/proxy/src/main/java/org/apache/rocketmq/proxy/grpc/v2/client/ClientActivity.java @@ -124,8 +124,10 @@ public CompletableFuture heartbeat(ProxyContext ctx, Heartbea break; } default: { + log.warn("heartbeat rejected unsupported client type. clientId:{}, clientType:{}", + ctx.getClientID(), clientSettings.getClientType()); future.complete(HeartbeatResponse.newBuilder() - .setStatus(ResponseBuilder.getInstance().buildStatus(Code.UNRECOGNIZED_CLIENT_TYPE, clientSettings.getClientType().name())) + .setStatus(buildUnsupportedClientTypeStatus(clientSettings.getClientType())) .build()); return future; } @@ -181,8 +183,10 @@ public CompletableFuture notifyClientTerminatio } break; default: + log.warn("client termination rejected unsupported client type. clientId:{}, clientType:{}", + clientId, clientSettings.getClientType()); future.complete(NotifyClientTerminationResponse.newBuilder() - .setStatus(ResponseBuilder.getInstance().buildStatus(Code.UNRECOGNIZED_CLIENT_TYPE, clientSettings.getClientType().name())) + .setStatus(buildUnsupportedClientTypeStatus(clientSettings.getClientType())) .build()); return future; } @@ -195,6 +199,12 @@ public CompletableFuture notifyClientTerminatio return future; } + private Status buildUnsupportedClientTypeStatus(ClientType clientType) { + String message = String.format("unsupported client type: %s. Proxy supports PRODUCER, PUSH_CONSUMER, " + + "SIMPLE_CONSUMER, LITE_PUSH_CONSUMER and LITE_SIMPLE_CONSUMER", clientType.name()); + return ResponseBuilder.getInstance().buildStatus(Code.UNRECOGNIZED_CLIENT_TYPE, message); + } + public CompletableFuture syncLiteSubscription(ProxyContext ctx, SyncLiteSubscriptionRequest request) { try { diff --git a/proxy/src/test/java/org/apache/rocketmq/proxy/grpc/v2/client/ClientActivityTest.java b/proxy/src/test/java/org/apache/rocketmq/proxy/grpc/v2/client/ClientActivityTest.java index e215c6efaba..957305e7105 100644 --- a/proxy/src/test/java/org/apache/rocketmq/proxy/grpc/v2/client/ClientActivityTest.java +++ b/proxy/src/test/java/org/apache/rocketmq/proxy/grpc/v2/client/ClientActivityTest.java @@ -212,6 +212,40 @@ public void testConsumerHeartbeat() throws Throwable { assertEquals("tag", data.getSubString()); } + @Test + public void testHeartbeatWithUnsupportedClientType() throws Throwable { + ProxyContext context = createContext(); + Settings settings = Settings.newBuilder() + .setClientType(ClientType.CLIENT_TYPE_UNSPECIFIED) + .build(); + when(this.grpcClientSettingsManager.getClientSettings(any())).thenReturn(settings); + + HeartbeatResponse response = this.clientActivity.heartbeat(context, HeartbeatRequest.newBuilder() + .setClientType(ClientType.CLIENT_TYPE_UNSPECIFIED) + .build()).get(); + + assertEquals(Code.UNRECOGNIZED_CLIENT_TYPE, response.getStatus().getCode()); + assertThat(response.getStatus().getMessage()).contains("unsupported client type: CLIENT_TYPE_UNSPECIFIED"); + assertThat(response.getStatus().getMessage()).contains("Proxy supports"); + } + + @Test + public void testNotifyClientTerminationWithUnsupportedClientType() throws Throwable { + ProxyContext context = createContext(); + Settings settings = Settings.newBuilder() + .setClientType(ClientType.CLIENT_TYPE_UNSPECIFIED) + .build(); + when(this.grpcClientSettingsManager.removeAndGetClientSettings(any())).thenReturn(settings); + + NotifyClientTerminationResponse response = this.clientActivity.notifyClientTermination( + context, + NotifyClientTerminationRequest.newBuilder().build()).get(); + + assertEquals(Code.UNRECOGNIZED_CLIENT_TYPE, response.getStatus().getCode()); + assertThat(response.getStatus().getMessage()).contains("unsupported client type: CLIENT_TYPE_UNSPECIFIED"); + assertThat(response.getStatus().getMessage()).contains("Proxy supports"); + } + protected void assertClientChannelInfo(ClientChannelInfo clientChannelInfo, String group) { assertEquals(LanguageCode.JAVA, clientChannelInfo.getLanguage()); assertEquals(CLIENT_ID, clientChannelInfo.getClientId());