In Message Queue for Apache RocketMQ, a group ID represents a consumer instance group. For most distributed applications, multiple consumer instances are often mounted to the same group ID. Subscription consistency means that the topics and tags of all consumer instances under the same group ID must be exactly the same.

Problem description

  • Consumer instances using the group ID have not received certain messages that they subscribed to. Log on to the Message Queue for Apache RocketMQ console, and choose Message > By Message ID. The query results show that the message has been consumed at least once, but the message logic shows that the message is not consumed.
  • Log on to the Message Queue for Apache RocketMQ console, and choose Groups > Consumer Status. On the page that appears, the value of Subscription Consistency is No.

Analysis

If the consumer instances under the same group ID are configured with different topics, or configured with different tags under the same topic, the subscription relationships of these consumer instances are inconsistent. If the subscription relationships are inconsistent, the message consumption logic is confusing, and even leads to message loss.

  • Possible cause 1

    Clients using the same group ID have subscribed to messages with different topics.

    Clients using the same group ID GID-MQ-FAQ subscribed to messages with different topics MQ-FAQ-TOPIC-1 and MQ-FAQ-TOPIC-2.

    Error example: code on JVM-1

    Properties properties = new Properties();
    properties.put(PropertyKeyConst.GROUP_ID, "GID-MQ-FAQ");
    Consumer consumer = ONSFactory.createConsumer(properties);
    consumer.subscribe("MQ-FAQ-TOPIC-1", "NM-MQ-FAQ", new MessageListener() {
        public Action consume(Message message, ConsumeContext context) {
            System.out.println("Receive: " + message);
            return Action.CommitMessage;
        }
    });
    consumer.start();                   

    Error example: code on JVM-2

     Properties properties = new Properties();
    properties.put(PropertyKeyConst.GROUP_ID, "GID-MQ-FAQ");
    Consumer consumer = ONSFactory.createConsumer(properties);
    consumer.subscribe("MQ-FAQ-TOPIC-2", "NM-MQ-FAQ", new MessageListener() {
        public Action consume(Message message, ConsumeContext context) {
            System.out.println("Receive: " + message);
            return Action.CommitMessage;
        }
    });
    
    consumer.start();                   
  • Possible cause 2

    Clients using the same group ID subscribed to messages with different tags under the same topic.

    Clients using the same group ID GID-MQ-FAQ subscribed to messages with different tags MQ-FAQ-TOPIC-1 and MQ-FAQ-TOPIC-2.

    Error example: code on JVM-1

    Properties properties = new Properties();
    properties.put(PropertyKeyConst.GROUP_ID, "GID-MQ-FAQ");
    Consumer consumer = ONSFactory.createConsumer(properties);
    consumer.subscribe("MQ-FAQ-TOPIC-1", "NM-MQ-FAQ", new MessageListener() {
        public Action consume(Message message, ConsumeContext context) {
            System.out.println("Receive: " + message);
            return Action.CommitMessage;
        }
    });
    consumer.start();                    

    Error example: code on JVM-2

     Properties properties = new Properties();
    properties.put(PropertyKeyConst.GROUP_ID, "GID-MQ-FAQ");
    Consumer consumer = ONSFactory.createConsumer(properties);
    consumer.subscribe("MQ-FAQ-TOPIC-2", "NM-MQ-FAQ", new MessageListener() {
        public Action consume(Message message, ConsumeContext context) {
            System.out.println("Receive: " + message);
            return Action.CommitMessage;
        }
    });
    
    consumer.start();                    

Solution

  1. Check the subscription codes of different clients. Ensure that the subscription relationships (including the subscribed topics and tags) of all clients with the same group ID are consistent.
  2. Restart all client applications.

Result verification

  • Restart all client applications.
  • Log on to the Message Queue for Apache RocketMQ console, and choose Groups > Consumer Status.On the page that appears, the value of Subscription Consistency is Yes.