You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by "zhaohai666 (via GitHub)" <gi...@apache.org> on 2026/04/02 03:28:36 UTC

[PR] Fix priority issue [rocketmq-clients]

zhaohai666 opened a new pull request, #1215:
URL: https://github.com/apache/rocketmq-clients/pull/1215

   Fix priority issue


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


Re: [PR] Fix priority issue.Supports lightweight messaging. [rocketmq-clients]

Posted by "zk-drizzle (via GitHub)" <gi...@apache.org>.
zk-drizzle commented on code in PR #1215:
URL: https://github.com/apache/rocketmq-clients/pull/1215#discussion_r3056729710


##########
nodejs/src/consumer/OffsetOption.ts:
##########
@@ -0,0 +1,167 @@
+/**
+ * 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.
+ */
+
+/**
+ * OffsetOption type enum.
+ */
+export enum OffsetType {
+  POLICY = 0,
+  OFFSET = 1,
+  TAIL_N = 2,
+  TIMESTAMP = 3,
+}
+
+/**
+ * ProtoBuf OffsetOption type.
+ */
+import { OffsetOption as ProtoOffsetOption } from '../../proto/apache/rocketmq/v2/definition_pb';
+
+/**
+ * OffsetOption for specifying consume from offset.
+ *
+ * <p>OffsetOption is used to specify the starting point for message consumption.
+ * It supports various policies and custom offsets.</p>
+ */
+export class OffsetOption {
+  /** Policy constant: last offset */
+  static readonly POLICY_LAST_VALUE = BigInt(0);
+
+  /** Policy constant: min offset */
+  static readonly POLICY_MIN_VALUE = BigInt(1);
+
+  /** Policy constant: max offset */
+  static readonly POLICY_MAX_VALUE = BigInt(2);
+
+  /** Predefined option: LAST_OFFSET */
+  static readonly LAST_OFFSET = new OffsetOption(OffsetType.POLICY, OffsetOption.POLICY_LAST_VALUE);
+
+  /** Predefined option: MIN_OFFSET */
+  static readonly MIN_OFFSET = new OffsetOption(OffsetType.POLICY, OffsetOption.POLICY_MIN_VALUE);
+
+  /** Predefined option: MAX_OFFSET */
+  static readonly MAX_OFFSET = new OffsetOption(OffsetType.POLICY, OffsetOption.POLICY_MAX_VALUE);
+
+  private readonly type: OffsetType;
+  private readonly value: bigint;
+
+  private constructor(type: OffsetType, value: bigint) {
+    this.type = type;
+    this.value = value;
+  }
+
+  /**
+   * Create an OffsetOption from a specific offset.
+   *
+   * @param offset - The offset value (must be >= 0)
+   * @return OffsetOption instance
+   * @throws Error if offset is negative
+   */
+  static ofOffset(offset: number | bigint): OffsetOption {
+    const value = typeof offset === 'number' ? BigInt(offset) : offset;
+    if (value < BigInt(0)) {
+      throw new Error('offset must be greater than or equal to 0');
+    }
+    return new OffsetOption(OffsetType.OFFSET, value);
+  }
+
+  /**
+   * Create an OffsetOption from tail N messages.
+   *
+   * @param tailN - Number of messages from the tail (must be >= 0)
+   * @return OffsetOption instance
+   * @throws Error if tailN is negative
+   */
+  static ofTailN(tailN: number | bigint): OffsetOption {
+    const value = typeof tailN === 'number' ? BigInt(tailN) : tailN;
+    if (value < BigInt(0)) {
+      throw new Error('tailN must be greater than or equal to 0');
+    }
+    return new OffsetOption(OffsetType.TAIL_N, value);
+  }
+
+  /**
+   * Create an OffsetOption from a timestamp.
+   *
+   * @param timestamp - Unix timestamp in milliseconds (must be >= 0)
+   * @return OffsetOption instance
+   * @throws Error if timestamp is negative
+   */
+  static ofTimestamp(timestamp: number | bigint): OffsetOption {
+    const value = typeof timestamp === 'number' ? BigInt(timestamp) : timestamp;
+    if (value < BigInt(0)) {
+      throw new Error('timestamp must be greater than or equal to 0');
+    }
+    return new OffsetOption(OffsetType.TIMESTAMP, value);
+  }
+
+  /**
+   * Get the type of this OffsetOption.
+   *
+   * @return OffsetType
+   */
+  getType(): OffsetType {
+    return this.type;
+  }
+
+  /**
+   * Get the value of this OffsetOption.
+   *
+   * @return Value as bigint
+   */
+  getValue(): bigint {
+    return this.value;
+  }
+
+  /**
+   * Returns a string representation of this OffsetOption.
+   *
+   * @return String representation
+   */
+  toString(): string {
+    return `OffsetOption{type=${OffsetType[this.type]}, value=${this.value}}`;
+  }
+
+  /**
+   * Convert this OffsetOption to ProtoBuf OffsetOption.
+   *
+   * @return ProtoBuf OffsetOption instance
+   */
+  toProtobuf(): ProtoOffsetOption {
+    const proto = new ProtoOffsetOption();

Review Comment:
   Add range safety check for BigInt-to-Number conversion
   
    if (this.value > BigInt(Number.MAX_SAFE_INTEGER) || this.value < BigInt(Number.MIN_SAFE_INTEGER)) {
       throw new Error(`Value ${this.value} is out of safe number range`);
     }



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


Re: [PR] Fix priority issue.Supports lightweight messaging. [rocketmq-clients]

Posted by "zk-drizzle (via GitHub)" <gi...@apache.org>.
zk-drizzle commented on code in PR #1215:
URL: https://github.com/apache/rocketmq-clients/pull/1215#discussion_r3057862545


##########
nodejs/src/producer/Producer.ts:
##########
@@ -302,6 +318,11 @@ export class Producer extends BaseClient {
       this.logger.info('Resend message successfully, topic=%s, messageId(s)=%s, maxAttempts=%d, attempt=%d, endpoints=%s, clientId=%s',
         topic, messageIds, maxAttempts, attempt, endpoints, this.clientId);
     }
+    // Log Lite Topic message sent successfully
+    if (sendReceipts.length > 0 && messages[0].liteTopic) {
+      this.logger.info('Lite Topic message sent successfully, topic=%s, liteTopic=%s, messageId=%s, clientId=%s',

Review Comment:
   Logs are printing too often.



##########
nodejs/src/producer/Producer.ts:
##########
@@ -207,11 +216,18 @@ export class Producer extends BaseClient {
     const topic = pubMessages[0].topic;
     const messageType = pubMessages[0].messageType;
     const messageGroup = pubMessages[0].messageGroup;
+    const liteTopic = pubMessages[0].liteTopic;
     const messageTypes = new Set(pubMessages.map(m => m.messageType));
     if (messageTypes.size > 1) {
       throw new TypeError(`Messages to send have different types=${JSON.stringify(Array.from(messageTypes))}`);
     }
 
+    // Log Lite Topic message sending
+    if (liteTopic) {

Review Comment:
   Logs are printing too often.



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


Re: [PR] Fix priority issue.Supports lightweight messaging. [rocketmq-clients]

Posted by "zk-drizzle (via GitHub)" <gi...@apache.org>.
zk-drizzle commented on code in PR #1215:
URL: https://github.com/apache/rocketmq-clients/pull/1215#discussion_r3071188500


##########
nodejs/src/client/TelemetrySession.ts:
##########
@@ -52,6 +52,16 @@ export class TelemetrySession {
     this.write(command);
   }
 
+  refresh() {

Review Comment:
   I recommend this approach.
   #isRefreshing: boolean = false;
   refresh() {
       if (this.#isRefreshing) {
         this.#logger.warn('Telemetry session refresh already in progress, skipping, endpoints=%s, clientId=%s',
           this.#endpoints, this.#baseClient.clientId);
         return;
       }
       
       this.#isRefreshing = true;
       this.#logger.info('Refreshing telemetry session, endpoints=%s, clientId=%s',
         this.#endpoints, this.#baseClient.clientId);
       
       try {
         this.release();
         this.#renewStream(false);
       } catch (err) {
         this.#logger.error('Failed to refresh telemetry session, endpoints=%s, clientId=%s, error=%s',
           this.#endpoints, this.#baseClient.clientId, err);
       } finally {
         this.#isRefreshing = false;
       }
     }



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


Re: [PR] Fix priority issue.Supports lightweight messaging. [rocketmq-clients]

Posted by "zk-drizzle (via GitHub)" <gi...@apache.org>.
zk-drizzle commented on code in PR #1215:
URL: https://github.com/apache/rocketmq-clients/pull/1215#discussion_r3056868401


##########
nodejs/src/consumer/ProcessQueue.ts:
##########
@@ -136,14 +138,23 @@ export class ProcessQueue {
       );
       this.#activityTime = Date.now();
 
+      (this.#consumer as any).logger?.info('Start to receive message, mq=%s@%s@%d, batchSize=%d, attemptId=%s',

Review Comment:
   The newly added logs are being printed too frequently. 



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


Re: [PR] Fix priority issue.Supports lightweight messaging. [rocketmq-clients]

Posted by "zk-drizzle (via GitHub)" <gi...@apache.org>.
zk-drizzle commented on code in PR #1215:
URL: https://github.com/apache/rocketmq-clients/pull/1215#discussion_r3056964381


##########
nodejs/src/consumer/PushConsumer.ts:
##########
@@ -470,4 +495,49 @@ export class PushConsumer extends Consumer {
     this.#processQueueTable.set(mqKey, { mq, pq: processQueue });
     return processQueue;
   }
+
+  /**
+   * Create a virtual process queue for Lite consumer.
+   * Lite consumers use a special message queue with queueId=-1 to receive messages.
+   * This method creates the virtual queue and starts fetching messages immediately.
+   *
+   * @param topic - The bind topic name
+   * @param filterExpression - The filter expression for message filtering
+   */
+  protected createVirtualProcessQueueForLite(topic: string, filterExpression: FilterExpression) {
+    // Create a virtual broker with default endpoints
+    const brokerPb = new (require('../../proto/apache/rocketmq/v2/definition_pb').Broker)();

Review Comment:
   The dynamic import here doesn't align with module best practices. I recommend using a static import at the top of the file instead.
   import { Broker as BrokerPB, MessageQueue as MessageQueuePB, Permission, MessageType } from '../../proto/apache/rocketmq/v2/definition_pb';
   



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


Re: [PR] Fix priority issue.Supports lightweight messaging. [rocketmq-clients]

Posted by "zk-drizzle (via GitHub)" <gi...@apache.org>.
zk-drizzle commented on code in PR #1215:
URL: https://github.com/apache/rocketmq-clients/pull/1215#discussion_r3062744906


##########
nodejs/src/consumer/OffsetOption.ts:
##########
@@ -0,0 +1,183 @@
+/**
+ * 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.
+ */
+
+/**
+ * OffsetOption type enum.
+ */
+export enum OffsetType {
+  POLICY = 0,
+  OFFSET = 1,
+  TAIL_N = 2,
+  TIMESTAMP = 3,
+}
+
+/**
+ * ProtoBuf OffsetOption type.
+ */
+import { OffsetOption as ProtoOffsetOption } from '../../proto/apache/rocketmq/v2/definition_pb';
+
+/**
+ * OffsetOption for specifying consume from offset.
+ *
+ * <p>OffsetOption is used to specify the starting point for message consumption.
+ * It supports various policies and custom offsets.</p>
+ */
+export class OffsetOption {
+  /** Policy constant: last offset */
+  static readonly POLICY_LAST_VALUE = BigInt(0);
+
+  /** Policy constant: min offset */
+  static readonly POLICY_MIN_VALUE = BigInt(1);
+
+  /** Policy constant: max offset */
+  static readonly POLICY_MAX_VALUE = BigInt(2);
+
+  /** Predefined option: LAST_OFFSET */
+  static readonly LAST_OFFSET = new OffsetOption(OffsetType.POLICY, OffsetOption.POLICY_LAST_VALUE);
+
+  /** Predefined option: MIN_OFFSET */
+  static readonly MIN_OFFSET = new OffsetOption(OffsetType.POLICY, OffsetOption.POLICY_MIN_VALUE);
+
+  /** Predefined option: MAX_OFFSET */
+  static readonly MAX_OFFSET = new OffsetOption(OffsetType.POLICY, OffsetOption.POLICY_MAX_VALUE);
+
+  private readonly type: OffsetType;
+  private readonly value: bigint;
+
+  private constructor(type: OffsetType, value: bigint) {
+    this.type = type;
+    this.value = value;
+  }
+
+  /**
+   * Create an OffsetOption from a specific offset.
+   *
+   * @param offset - The offset value (must be >= 0)
+   * @return OffsetOption instance
+   * @throws Error if offset is negative
+   */
+  static ofOffset(offset: number | bigint): OffsetOption {
+    const value = typeof offset === 'number' ? BigInt(offset) : offset;
+    if (value < BigInt(0)) {
+      throw new Error('offset must be greater than or equal to 0');
+    }
+    return new OffsetOption(OffsetType.OFFSET, value);
+  }
+
+  /**
+   * Create an OffsetOption from tail N messages.
+   *
+   * @param tailN - Number of messages from the tail (must be >= 0)
+   * @return OffsetOption instance
+   * @throws Error if tailN is negative
+   */
+  static ofTailN(tailN: number | bigint): OffsetOption {
+    const value = typeof tailN === 'number' ? BigInt(tailN) : tailN;
+    if (value < BigInt(0)) {
+      throw new Error('tailN must be greater than or equal to 0');
+    }
+    return new OffsetOption(OffsetType.TAIL_N, value);
+  }
+
+  /**
+   * Create an OffsetOption from a timestamp.
+   *
+   * @param timestamp - Unix timestamp in milliseconds (must be >= 0)
+   * @return OffsetOption instance
+   * @throws Error if timestamp is negative
+   */
+  static ofTimestamp(timestamp: number | bigint): OffsetOption {
+    const value = typeof timestamp === 'number' ? BigInt(timestamp) : timestamp;
+    if (value < BigInt(0)) {
+      throw new Error('timestamp must be greater than or equal to 0');
+    }
+    return new OffsetOption(OffsetType.TIMESTAMP, value);
+  }
+
+  /**
+   * Get the type of this OffsetOption.
+   *
+   * @return OffsetType
+   */
+  getType(): OffsetType {
+    return this.type;
+  }
+
+  /**
+   * Get the value of this OffsetOption.
+   *
+   * @return Value as bigint
+   */
+  getValue(): bigint {
+    return this.value;
+  }
+
+  /**
+   * Returns a string representation of this OffsetOption.
+   *
+   * @return String representation
+   */
+  toString(): string {
+    return `OffsetOption{type=${OffsetType[this.type]}, value=${this.value}}`;
+  }
+
+  /**
+   * Convert this OffsetOption to ProtoBuf OffsetOption.
+   *
+   * @return ProtoBuf OffsetOption instance
+   */
+  toProtobuf(): ProtoOffsetOption {
+    const proto = new ProtoOffsetOption();
+    switch (this.type) {
+      case OffsetType.POLICY: {
+        // Map our policy values to ProtoBuf Policy enum
+        // POLICY_LAST_VALUE (0) -> Policy.LAST (0)
+        // POLICY_MIN_VALUE (1) -> Policy.MIN (1)
+        // POLICY_MAX_VALUE (2) -> Policy.MAX (2)
+        if (this.value > BigInt(Number.MAX_SAFE_INTEGER) || this.value < BigInt(Number.MIN_SAFE_INTEGER)) {
+          throw new Error(`Value ${this.value} is out of safe number range`);
+        }
+        proto.setPolicy(Number(this.value));
+        break;
+      }
+      case OffsetType.OFFSET: {
+        if (this.value > BigInt(Number.MAX_SAFE_INTEGER) || this.value < BigInt(Number.MIN_SAFE_INTEGER)) {

Review Comment:
   I think the logic for checking the scope can be abstracted into a method.
    private validateSafeNumberRange(value: bigint): void {
       if (value > BigInt(Number.MAX_SAFE_INTEGER) || value < BigInt(Number.MIN_SAFE_INTEGER)) {
         throw new Error(`Value ${value} is out of safe number range`);
       }
     }



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


Re: [PR] Fix priority issue.Supports lightweight messaging. [rocketmq-clients]

Posted by "zk-drizzle (via GitHub)" <gi...@apache.org>.
zk-drizzle commented on code in PR #1215:
URL: https://github.com/apache/rocketmq-clients/pull/1215#discussion_r3057794609


##########
nodejs/src/message/Message.ts:
##########
@@ -49,6 +51,26 @@ export class Message {
       if (options.messageGroup) {
         throw new Error('priority and messageGroup should not be set at same time');
       }
+      if (options.liteTopic) {
+        throw new Error('priority and liteTopic should not be set at same time');
+      }
+    }
+
+    // Validate mutual exclusivity - liteTopic
+    if (options.liteTopic !== undefined) {
+      if (options.deliveryTimestamp) {
+        throw new Error('liteTopic and deliveryTimestamp should not be set at same time');
+      }
+      if (options.messageGroup) {
+        throw new Error('liteTopic and messageGroup should not be set at same time');
+      }
+    }
+
+    // Validate mutual exclusivity - deliveryTimestamp
+    if (options.deliveryTimestamp !== undefined) {

Review Comment:
   Also add checks for delay



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


Re: [PR] Fix priority issue.Supports lightweight messaging. [rocketmq-clients]

Posted by "zk-drizzle (via GitHub)" <gi...@apache.org>.
zk-drizzle commented on code in PR #1215:
URL: https://github.com/apache/rocketmq-clients/pull/1215#discussion_r3056643636


##########
nodejs/src/consumer/LiteSubscriptionManager.ts:
##########
@@ -0,0 +1,349 @@
+/**
+ * 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.
+ */
+
+import { LiteSubscriptionAction } from '../../proto/apache/rocketmq/v2/definition_pb';
+import {
+  NotifyUnsubscribeLiteCommand,
+  SyncLiteSubscriptionRequest,
+  SyncLiteSubscriptionResponse,
+} from '../../proto/apache/rocketmq/v2/service_pb';
+import { ClientException } from '../exception';
+import { Resource } from '../route';
+import { LitePushConsumerImpl } from './LitePushConsumerImpl';
+import { OffsetOption } from './OffsetOption';
+
+const SYNC_LITE_SUBSCRIPTION_INTERVAL = 30000; // 30 seconds
+
+/**
+ * Manages lite topic subscriptions for LitePushConsumer.
+ *
+ * <p>LiteSubscriptionManager handles:
+ * - Maintaining the set of subscribed lite topics
+ * - Periodic synchronization of lite subscriptions with server
+ * - Quota management and verification
+ * - Handling unsubscribe commands from server</p>
+ */
+export class LiteSubscriptionManager {
+  private readonly consumerImpl: LitePushConsumerImpl;
+  private readonly bindTopic: Resource;
+  private readonly group: Resource;
+  private readonly liteTopicSet = new Set<string>();
+  private liteSubscriptionQuota: number;
+  private maxLiteTopicSize: number;
+  private syncTimer?: NodeJS.Timeout;
+
+  constructor(
+    consumerImpl: LitePushConsumerImpl,
+    bindTopic: Resource,
+    group: Resource,
+  ) {
+    this.consumerImpl = consumerImpl;
+    this.bindTopic = bindTopic;
+    this.group = group;
+    this.liteSubscriptionQuota = 100; // Default quota
+    this.maxLiteTopicSize = 64; // Default max length
+  }
+
+  /**
+   * Start periodic sync of lite subscriptions.
+   */
+  public startUp() {
+    this.syncTimer = setInterval(
+      () => this.syncAllLiteSubscription(),
+      SYNC_LITE_SUBSCRIPTION_INTERVAL,
+    );
+  }
+
+  /**
+   * Stop the sync timer.
+   */
+  public shutdown() {
+    if (this.syncTimer) {
+      clearInterval(this.syncTimer);
+      this.syncTimer = undefined;
+    }
+  }
+
+  /**
+   * Get the bind topic name.
+   */
+  public getBindTopicName(): string {
+    return this.bindTopic.getName();
+  }
+
+  /**
+   * Get the consumer group name.
+   */
+  public getConsumerGroupName(): string {
+    return this.group.getName();
+  }
+
+  /**
+   * Get a copy of the lite topic set.
+   */
+  public getLiteTopicSet(): Set<string> {
+    return new Set(this.liteTopicSet);
+  }
+
+  /**
+   * Sync settings from server.
+   */
+  public sync(settings: any) {
+    if (!settings?.hasSubscription?.()) {
+      return;
+    }
+
+    const subscription = settings.getSubscription();
+    if (subscription.hasLiteSubscriptionQuota?.()) {
+      this.liteSubscriptionQuota = subscription.getLiteSubscriptionQuota();
+    }
+    if (subscription.hasMaxLiteTopicSize?.()) {
+      this.maxLiteTopicSize = subscription.getMaxLiteTopicSize();
+    }
+  }
+
+  /**
+   * Subscribe to a lite topic.
+   */
+  public async subscribeLite(
+    liteTopic: string,
+    offsetOption?: OffsetOption | null,
+  ): Promise<void> {
+    // Check if consumer is running
+    if (!this.consumerImpl.isRunning()) {
+      throw new ClientException(500, 'Consumer is not running');
+    }
+
+    // Already subscribed
+    if (this.liteTopicSet.has(liteTopic)) {
+      return;
+    }
+
+    // Validate lite topic
+    this.validateLiteTopic(liteTopic);
+
+    // Check quota
+    this.checkLiteSubscriptionQuota(1);
+
+    try {
+      await this.syncLiteSubscription(
+        LiteSubscriptionAction.PARTIAL_ADD,
+        [ liteTopic ],
+        offsetOption ?? null,
+      );
+
+      this.liteTopicSet.add(liteTopic);
+      this.consumerImpl.getLogger().info(
+        'SubscribeLite %s, topic=%s, group=%s, clientId=%s',
+        liteTopic,
+        this.getBindTopicName(),
+        this.getConsumerGroupName(),
+        this.consumerImpl.clientId,
+      );
+    } catch (error) {
+      this.consumerImpl.getLogger().error(
+        'Failed to subscribeLite %s, error=%s',
+        liteTopic,
+        error,
+      );
+      throw error;
+    }
+  }
+
+  /**
+   * Unsubscribe from a lite topic.
+   */
+  public async unsubscribeLite(liteTopic: string): Promise<void> {
+    // Check if consumer is running
+    if (!this.consumerImpl.isRunning()) {
+      throw new ClientException(500, 'Consumer is not running');
+    }
+
+    // Not subscribed
+    if (!this.liteTopicSet.has(liteTopic)) {
+      return;
+    }
+
+    try {
+      await this.syncLiteSubscription(
+        LiteSubscriptionAction.PARTIAL_REMOVE,
+        [ liteTopic ],
+        null,
+      );
+
+      this.liteTopicSet.delete(liteTopic);
+      this.consumerImpl.getLogger().info(
+        'UnsubscribeLite %s, topic=%s, group=%s, clientId=%s',
+        liteTopic,
+        this.getBindTopicName(),
+        this.getConsumerGroupName(),
+        this.consumerImpl.clientId,
+      );
+    } catch (error) {
+      this.consumerImpl.getLogger().error(
+        'Failed to unsubscribeLite %s, error=%s',
+        liteTopic,
+        error,
+      );
+      throw error;
+    }
+  }
+
+  /**
+   * Periodic sync of all lite subscriptions.
+   */
+  private async syncAllLiteSubscription() {
+    try {
+      this.checkLiteSubscriptionQuota(0);
+      await this.syncLiteSubscription(
+        LiteSubscriptionAction.COMPLETE_ADD,
+        Array.from(this.liteTopicSet),
+        null,
+      );
+    } catch (error) {
+      this.consumerImpl.getLogger().error(
+        'Schedule syncAllLiteSubscription error, clientId=%s, error=%s',
+        this.consumerImpl.clientId,
+        error,
+      );
+    }
+  }
+
+  /**
+   * Sync lite subscription with server.
+   */
+  private async syncLiteSubscription(
+    action: LiteSubscriptionAction,
+    liteTopics: string[],
+    offsetOption: OffsetOption | null,
+  ): Promise<void> {
+    const logger = this.consumerImpl.getLogger();
+    if (logger.debug) {
+      logger.debug(
+        'SyncLiteSubscription: action=%s, liteTopics=[%s], offsetOption=%s',
+        LiteSubscriptionAction[action],
+        liteTopics.join(', '),
+        offsetOption?.toString() ?? 'null',
+      );
+    }
+
+    // Build the request
+    const request = new SyncLiteSubscriptionRequest()
+      .setAction(action)
+      .setTopic(this.bindTopic.toProtobuf())
+      .setGroup(this.group.toProtobuf())
+      .setLiteTopicSetList(liteTopics);
+
+    // Set offset option if provided
+    if (offsetOption) {
+      request.setOffsetOption(offsetOption.toProtobuf());
+    }
+
+    try {
+      // Call RPC client using public methods from LitePushConsumerImpl
+      const response: SyncLiteSubscriptionResponse = await this.consumerImpl.getRpcClientManager().syncLiteSubscription(
+        this.consumerImpl.getEndpoints(),
+        request,
+        this.consumerImpl.getRequestTimeout(),
+      );
+
+      // Handle response status
+      const status = response.getStatus();
+      if (status && status.getCode() !== 20000) { // Code.OK

Review Comment:
   We could use constants to make the code more elegant
   
   readonly SUCCESS_CODE = 20000;



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


Re: [PR] Fix priority issue.Supports lightweight messaging. [rocketmq-clients]

Posted by "zk-drizzle (via GitHub)" <gi...@apache.org>.
zk-drizzle commented on code in PR #1215:
URL: https://github.com/apache/rocketmq-clients/pull/1215#discussion_r3062669035


##########
nodejs/examples/LitePushConsumerExample.ts:
##########
@@ -0,0 +1,107 @@
+/**
+ * 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.
+ */
+
+/**
+ * LitePushConsumer Example
+ *
+ * This example demonstrates how to use LitePushConsumer to consume messages
+ * from lite topics with reduced overhead.
+ *
+ * Prerequisites:
+ * - RocketMQ server with lite topic support enabled
+ * - A parent topic created on the server
+ * - Consumer group registered on the server
+ */
+
+import {
+  LitePushConsumerBuilder,
+  ConsumeResult,
+  OffsetOption,
+  type MessageView,
+} from '../src';
+import { endpoints, namespace, consumerGroup } from './ProducerSingleton';
+
+async function main() {
+  console.log('========== LitePushConsumer Example ==========\n');
+
+  // Create and start LitePushConsumer using builder pattern
+  const consumer = await new LitePushConsumerBuilder()
+    .setClientConfiguration({
+      endpoints,
+      namespace,
+    })
+    .setConsumerGroup(consumerGroup)
+    .bindTopic('your-parent-topic') // Replace with your actual parent topic
+    .setMessageListener({
+      async consume(messageView: MessageView) {
+        console.log('Received message:', {
+          messageId: messageView.messageId,
+          topic: messageView.topic,
+          liteTopic: messageView.liteTopic,
+          tag: messageView.tag,
+          keys: messageView.keys,
+          body: messageView.body.toString('utf-8'),
+        });
+        return ConsumeResult.SUCCESS;
+      },
+    })
+    .setMaxCacheMessageCount(1024)
+    .setMaxCacheMessageSizeInBytes(64 * 1024 * 1024) // 64MB
+    .setConsumptionThreadCount(20)
+    .startup();
+
+  console.log('✓ Consumer started successfully\n');
+
+  try {
+    // Subscribe to lite topics with different offset strategies
+    console.log('Subscribing to lite topics...\n');
+
+    await consumer.subscribeLite('lite-topic-1');
+    console.log('✓ Subscribed to lite-topic-1 (from last offset)');
+
+    await consumer.subscribeLite('lite-topic-2', OffsetOption.MIN_OFFSET);
+    console.log('✓ Subscribed to lite-topic-2 (from minimum offset)');
+
+    await consumer.subscribeLite('lite-topic-3', OffsetOption.ofTailN(100));
+    console.log('✓ Subscribed to lite-topic-3 (last 100 messages)\n');
+
+    // Check current subscriptions
+    const topics = consumer.getLiteTopicSet();
+    console.log(`Current subscriptions (${topics.size} topics):`);
+    topics.forEach(topic => console.log(`  - ${topic}`));
+    console.log();

Review Comment:
   I suggest removing this.



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


Re: [PR] Fix priority issue.Supports lightweight messaging. [rocketmq-clients]

Posted by "zk-drizzle (via GitHub)" <gi...@apache.org>.
zk-drizzle commented on code in PR #1215:
URL: https://github.com/apache/rocketmq-clients/pull/1215#discussion_r3056969388


##########
nodejs/src/consumer/PushConsumer.ts:
##########
@@ -470,4 +495,49 @@ export class PushConsumer extends Consumer {
     this.#processQueueTable.set(mqKey, { mq, pq: processQueue });
     return processQueue;
   }
+
+  /**
+   * Create a virtual process queue for Lite consumer.
+   * Lite consumers use a special message queue with queueId=-1 to receive messages.
+   * This method creates the virtual queue and starts fetching messages immediately.
+   *
+   * @param topic - The bind topic name
+   * @param filterExpression - The filter expression for message filtering
+   */
+  protected createVirtualProcessQueueForLite(topic: string, filterExpression: FilterExpression) {

Review Comment:
   We should add necessary validation for the topic and filterExpression 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


Re: [PR] Fix priority issue.Supports lightweight messaging. [rocketmq-clients]

Posted by "zk-drizzle (via GitHub)" <gi...@apache.org>.
zk-drizzle commented on code in PR #1215:
URL: https://github.com/apache/rocketmq-clients/pull/1215#discussion_r3055329151


##########
nodejs/src/consumer/Consumer.ts:
##########
@@ -126,4 +127,25 @@ export abstract class Consumer extends BaseClient {
     const res = await this.rpcClientManager.forwardMessageToDeadLetterQueue(endpoints, request, timeout);
     return res;
   }
+
+  /**
+   * Get the consumer group name.
+   *
+   * @return Consumer group name
+   */
+  getConsumerGroup(): string {
+    return this.consumerGroup;
+  }
+
+  /**
+   * Check if this is a lite consumer.
+   *
+   * @return true if this is a LITE_PUSH_CONSUMER or LITE_SIMPLE_CONSUMER
+   */
+  protected isLiteConsumer(): boolean {

Review Comment:
   Let's keep it simple.
   
   protected isLiteConsumer(): boolean {
     const clientType = this.getClientType();
     return clientType === ClientType.LITE_PUSH_CONSUMER 
         || clientType === ClientType.LITE_SIMPLE_CONSUMER;
   }



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


Re: [PR] Fix priority issue.Supports lightweight messaging. [rocketmq-clients]

Posted by "zk-drizzle (via GitHub)" <gi...@apache.org>.
zk-drizzle commented on code in PR #1215:
URL: https://github.com/apache/rocketmq-clients/pull/1215#discussion_r3057600149


##########
nodejs/src/consumer/StandardConsumeService.ts:
##########
@@ -19,24 +19,37 @@ import { MessageView } from '../message';
 import { ConsumeService } from './ConsumeService';
 import { MessageListener } from './MessageListener';
 import type { ProcessQueue } from './ProcessQueue';
+import { getDefaultLogger } from '../client';
 
 export class StandardConsumeService extends ConsumeService {
+  private readonly logger = getDefaultLogger();
+
+  // eslint-disable-next-line @typescript-eslint/no-useless-constructor
   constructor(clientId: string, messageListener: MessageListener) {
     super(clientId, messageListener);
   }
 
   consume(pq: ProcessQueue, messageViews: MessageView[]): void {
+    this.logger.info('StandardConsumeService.consume called, messageCount=%d', messageViews.length);

Review Comment:
   We should reduce the frequency of these logs.



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


Re: [PR] Fix priority issue.Supports lightweight messaging. [rocketmq-clients]

Posted by "zk-drizzle (via GitHub)" <gi...@apache.org>.
zk-drizzle commented on code in PR #1215:
URL: https://github.com/apache/rocketmq-clients/pull/1215#discussion_r3057740469


##########
nodejs/src/message/Message.ts:
##########
@@ -49,6 +51,26 @@ export class Message {
       if (options.messageGroup) {
         throw new Error('priority and messageGroup should not be set at same time');
       }
+      if (options.liteTopic) {
+        throw new Error('priority and liteTopic should not be set at same time');
+      }
+    }
+
+    // Validate mutual exclusivity - liteTopic
+    if (options.liteTopic !== undefined) {
+      if (options.deliveryTimestamp) {
+        throw new Error('liteTopic and deliveryTimestamp should not be set at same time');
+      }

Review Comment:
   Same as above



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


Re: [PR] Fix priority issue.Supports lightweight messaging. [rocketmq-clients]

Posted by "zk-drizzle (via GitHub)" <gi...@apache.org>.
zk-drizzle commented on code in PR #1215:
URL: https://github.com/apache/rocketmq-clients/pull/1215#discussion_r3057731064


##########
nodejs/src/message/Message.ts:
##########


Review Comment:
   We should validate that priority and delay settings are mutually exclusive.



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


Re: [PR] Fix priority issue.Supports lightweight messaging. [rocketmq-clients]

Posted by "RongtongJin (via GitHub)" <gi...@apache.org>.
RongtongJin merged PR #1215:
URL: https://github.com/apache/rocketmq-clients/pull/1215


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