Symptoms

Multiple consumers are started on different Java Virtual Machines (JVMs). For consumers under the same group ID, different topics are configured, or topics are the same but tags are different. As a result, the subscription relationships are inconsistent, and messages do not meet the expectations.

Sample of the incorrect code

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

    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();            

    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();
  • Example 2: Consumers using the same group ID GID-MQ-FAQ subscribed to messages with different tags NM-MQ-FAQ-1 and NM-MQ-FAQ-2 of the same topic.

    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-1", new MessageListener() {
            public Action consume(Message message, ConsumeContext context) {
                System.out.println("Receive: " + message);
                return Action.CommitMessage;
            }
        });
        consumer.start();
    					

    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-1", "NM-MQ-FAQ-2", new MessageListener() {
            public Action consume(Message message, ConsumeContext context) {
                System.out.println("Receive: " + message);
                return Action.CommitMessage;
            }
        });
    
        consumer.start();

Recommended solution

When the same group ID is used to start multiple consumers on different JVMs, ensure that the topics and tags configured for these consumers are consistent.