edit-icon download-icon

Inconsistent subscriptions

Last Updated: Feb 24, 2018

Problem description

Multiple Consumers have been started in different JVMs, and different Topics have been assigned to the same Consumer IDs, or same Topics with different Tags have been assigned to the same Consumer IDs, causing inconsistent subscriptions. As a result, the messages do not meet the expectation.

Error code examples

Example 1: A Consumer ID (CID-MQ-FAQ) subscribes to different Topics (MQ-FAQ-TOPIC-1 and MQ-FAQ-TOPIC-2).

Code on JVM-1:

  1. Properties properties = new Properties();
  2. properties.put(PropertyKeyConst.ConsumerId, "CID-MQ-FAQ");
  3. Consumer consumer = ONSFactory.createConsumer(properties);
  4. consumer.subscribe("MQ-FAQ-TOPIC-1", "NM-MQ-FAQ", new MessageListener() {
  5. public Action consume(Message message, ConsumeContext context) {
  6. System.out.println("Receive: " + message);
  7. return Action.CommitMessage;
  8. }
  9. });
  10. consumer.start();

Code on JVM-2:

  1. Properties properties = new Properties();
  2. properties.put(PropertyKeyConst.ConsumerId, "CID-MQ-FAQ");
  3. Consumer consumer = ONSFactory.createConsumer(properties);
  4. consumer.subscribe("MQ-FAQ-TOPIC-2", "NM-MQ-FAQ", new MessageListener() {
  5. public Action consume(Message message, ConsumeContext context) {
  6. System.out.println("Receive: " + message);
  7. return Action.CommitMessage;
  8. }
  9. });
  10. consumer.start();

Example 2: A Consumer ID (CID-MQ-FAQ) subscribes to the same Topic with different tags (NM-MQ-FAQ-1 and NM-MQ-FAQ-2).

Code on JVM-1:

  1. Properties properties = new Properties();
  2. properties.put(PropertyKeyConst.ConsumerId, "CID-MQ-FAQ");
  3. Consumer consumer = ONSFactory.createConsumer(properties);
  4. consumer.subscribe("MQ-FAQ-TOPIC-1", "NM-MQ-FAQ-1", new MessageListener() {
  5. public Action consume(Message message, ConsumeContext context) {
  6. System.out.println("Receive: " + message);
  7. return Action.CommitMessage;
  8. }
  9. });
  10. consumer.start();

Code on JVM-2:

  1. Properties properties = new Properties();
  2. properties.put(PropertyKeyConst.ConsumerId, "CID-MQ-FAQ");
  3. Consumer consumer = ONSFactory.createConsumer(properties);
  4. consumer.subscribe("MQ-FAQ-TOPIC-1", "NM-MQ-FAQ-2", new MessageListener() {
  5. public Action consume(Message message, ConsumeContext context) {
  6. System.out.println("Receive: " + message);
  7. return Action.CommitMessage;
  8. }
  9. });
  10. consumer.start();

Suggested solution

When multiple Consumers with the same Consumer IDs are started in different JVMs, please make sure that the Topics and Tags are consistent.

Thank you! We've received your feedback.