This is an automated email from the ASF dual-hosted git repository.
jinrongtong pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-clients.git
The following commit(s) were added to refs/heads/master by this push:
new e05d5a98 [Golang] fix(client.go): fix bug where
NotifyClientTermination was never called (#1221)
e05d5a98 is described below
commit e05d5a9890772fd80dfa709d555006c88f99f568
Author: Quan <[email protected]>
AuthorDate: Wed Apr 15 18:13:22 2026 +0800
[Golang] fix(client.go): fix bug where NotifyClientTermination was never
called (#1221)
* fix(client.go): fix bug where NotifyClientTermination was never called
Fixed logic error in `notifyClientTermination` method. The previous
implementation incorrectly checked `err != nil` instead of `endpoints != nil`,
which prevented `NotifyClientTermination` from being called. Added proper error
handling with detailed logging for each notification attempt.
Change-Id: I05c41d18419d107877150f623d97eedc29dcd546
* fix(client.go): add resource group to client termination notification
request
Added resource group information to the client termination notification
request, including namespace and consumer group name.
Change-Id: I26d28ad6f8e6ddf46f49ad5c01c7c0aac40135c3
* fix(process_queue.go): Improve message reception exception handling logic
Optimized the logging strategy when errors occur during message reception,
with special handling for cases where no new messages are found to avoid
unnecessary error log output. Meanwhile, the detailed error logging mechanism
for other exceptional cases is preserved.
Change-Id: I4b0ef5d2c41fea0727ff6950cbf415b4f935e20b
* refactor(lite_push_consumer.go): extract variables and optimize logging
Extracted `topic` and `group` variables from the `syncLiteSubscription`
method and adjusted log output formats based on different action types, making
the code more readable and logs more detailed.
Change-Id: Iba358e912af41266d84680435c682a5e19f55711
---
golang/client.go | 18 ++++++++++++++----
golang/lite_push_consumer.go | 17 +++++++++++++++--
golang/process_queue.go | 17 +++++++++++------
3 files changed, 40 insertions(+), 12 deletions(-)
diff --git a/golang/client.go b/golang/client.go
index af8c24f6..10854bda 100644
--- a/golang/client.go
+++ b/golang/client.go
@@ -610,17 +610,27 @@ func routeEqual(old, new []*v2.MessageQueue) bool {
}
func (cli *defaultClient) notifyClientTermination() {
- cli.log.Info("start notifyClientTermination")
ctx := cli.Sign(context.Background())
- request := &v2.NotifyClientTerminationRequest{}
+ request := &v2.NotifyClientTerminationRequest{
+ Group: &v2.Resource{
+ ResourceNamespace: cli.config.NameSpace,
+ Name: cli.config.ConsumerGroup,
+ },
+ }
targets := cli.getTotalTargets()
for _, target := range targets {
- endpoints, err := utils.ParseTarget(target)
+ endpoints, _ := utils.ParseTarget(target)
+ if endpoints == nil {
+ continue
+ }
+ cli.log.Infof("start notifyClientTermination, endpoints=%s",
utils.EndpointsToString(endpoints))
+ _, err := cli.clientManager.NotifyClientTermination(ctx,
endpoints, request, cli.opts.timeout)
if err != nil {
- cli.clientManager.NotifyClientTermination(ctx,
endpoints, request, cli.opts.timeout)
+ cli.log.Errorf("failed to notify client termination,
endpoints=%s, error=%v", utils.EndpointsToString(endpoints), err)
}
}
}
+
func (cli *defaultClient) GracefulStop() error {
if !cli.on.CAS(true, false) {
return fmt.Errorf("client has been closed")
diff --git a/golang/lite_push_consumer.go b/golang/lite_push_consumer.go
index e78cd1b4..c16229ca 100644
--- a/golang/lite_push_consumer.go
+++ b/golang/lite_push_consumer.go
@@ -157,16 +157,29 @@ func (lpc *defaultLitePushConsumer)
syncAllLiteSubscription() {
}
func (lpc *defaultLitePushConsumer) syncLiteSubscription(context
context.Context, action v2.LiteSubscriptionAction, diff []string) error {
+ topic := lpc.litePushConsumerSettings.bindTopic
+ group := lpc.litePushConsumerSettings.groupName
+ clientId := lpc.litePushConsumerSettings.clientId
+
endpoints := lpc.cli.accessPoint
request := v2.SyncLiteSubscriptionRequest{
Action: action,
Topic: &v2.Resource{
- Name:
lpc.litePushConsumerSettings.bindTopic,
+ Name: topic,
ResourceNamespace: lpc.cli.config.NameSpace,
},
- Group: lpc.litePushConsumerSettings.groupName,
+ Group: group,
LiteTopicSet: diff,
}
+
+ if action == v2.LiteSubscriptionAction_COMPLETE_ADD {
+ sugarBaseLogger.Infof("syncLiteSubscription action:%s,
topic:%s, group:%s, clientId:%s, liteTopicCount:%d",
+ action, topic, group, clientId, len(diff))
+ } else {
+ sugarBaseLogger.Infof("syncLiteSubscription action:%s,
topic:%s, group:%s, clientId:%s, liteTopics:%v",
+ action, topic, group, clientId, diff)
+ }
+
context = lpc.cli.Sign(context)
if v, err :=
lpc.defaultPushConsumer.cli.clientManager.SyncLiteSubscription(context,
endpoints, &request, lpc.pcSettings.requestTimeout); err != nil {
return err
diff --git a/golang/process_queue.go b/golang/process_queue.go
index 63e709b2..0af768d9 100644
--- a/golang/process_queue.go
+++ b/golang/process_queue.go
@@ -461,12 +461,17 @@ func (dpq *defaultProcessQueue)
receiveMessageImmediatelyWithAttemptId(attemptId
if status.Code(err) == codes.DeadlineExceeded {
nextAttemptId = request.GetAttemptId()
}
- dpq.consumer.cli.doAfter(MessageHookPoints_RECEIVE,
make([]*MessageCommon, 0), duration, MessageHookPointsStatus_ERROR)
- // add some check to skip no message
- dpq.consumer.cli.log.Errorf("Exception raised during
message reception, mq=%s, endpoints=%v, attemptId=%d, "+
- "nextAttemptId=%s, clientId=%s, err=%w",
dpq.mqstr, endpoints, request.GetAttemptId(), nextAttemptId,
- clientId, err)
-
+ rpcErr, isRpcErr := AsErrRpcStatus(err)
+ isNoNewMessage := isRpcErr && rpcErr.GetCode() ==
int32(v2.Code_MESSAGE_NOT_FOUND)
+ if isNoNewMessage {
+ dpq.consumer.cli.log.Debugf("No new message,
mq=%s, endpoints=%v, clientId=%s",
+ dpq.mqstr, endpoints, clientId)
+ } else {
+
dpq.consumer.cli.doAfter(MessageHookPoints_RECEIVE, make([]*MessageCommon, 0),
duration, MessageHookPointsStatus_ERROR)
+ dpq.consumer.cli.log.Errorf("Exception raised
during message reception, mq=%s, endpoints=%v, attemptId=%d, "+
+ "nextAttemptId=%s, clientId=%s,
err=%w", dpq.mqstr, endpoints, request.GetAttemptId(), nextAttemptId,
+ clientId, err)
+ }
dpq.onReceiveMessageException(err, nextAttemptId)
}
}()