I am trying to use MQ shared subscription, which is not working when I have multiple instances of my micro-service up and running.
My DefaultJmsListenerContainerFactory configuration is as mentioned below, where I am using factory.setSubscriptionShared(true).
@Bean
@Qualifier("subscriberListenerContainerFactory")
public DefaultJmsListenerContainerFactory subscriberListenerContainerFactory(@Qualifier("subscriberConnectionFactory") ConnectionFactory subscriberConnectionFactory) {
DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
factory.setConnectionFactory(subscriberConnectionFactory);
factory.setDestinationResolver(new MyDestinationTopicResolver("Topic-JNDI-Name", "Topic-Name"));
factory.setSubscriptionShared(true);
factory.setPubSubDomain(true);
factory.setSessionTransacted(true);
factory.setSubscriptionDurable(true);
factory.setConcurrency("1-1");
return factory;
}
My listener config is shown below:
@JmsListener(subscription = "My-Test-Subscription", destination = "dummy", containerFactory = "subscriberListenerContainerFactory", selector = "message_sub_type = 'MY_EVENT'")
public void onMessage(Message message) throws JAXBException { ... }
When I try to run multiple instances of this service, I get following error in all instances:
Caused by: com.ibm.mq.MQException: JMSCMQ0001: IBM MQ call failed with compcode '1' ('MQCC_WARNING') reason '2429' ('MQRC_SUBSCRIPTION_IN_USE')
I want to use shared subscription so that only one instance of the service gets the message from topic.
NOTE: Previously we had same subscription but it was not shared and not durable. Then we made it shared and durable. After that first time, it worked fine. Now when we are trying to change the subscription name or client id, we are getting above error. I understand that if it is durable subscription, then the subscription will be present in IBM MQ Server, and due to that, when we are trying to make any change in durable subscription, we are getting error: '2429' ('MQRC_SUBSCRIPTION_IN_USE'). But we are not able to see the durable subscription in MQ explorer, still we are getting MQRC_SUBSCRIPTION_IN_USE error.
Is there a possibility that the previous durable subscription is in some inconsistent state (like stale or uncommitted)?