|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
MQ 9 - Shared subscription on topic JMS 2.0 |
« View previous topic :: View next topic » |
Author |
Message
|
TucoBouch |
Posted: Wed Feb 13, 2019 10:48 pm Post subject: MQ 9 - Shared subscription on topic JMS 2.0 |
|
|
Newbie
Joined: 13 Feb 2019 Posts: 2
|
Hi,
I'm facing problem when developing an application that subscribe a MQ Topic (MQ version 9).
I need to do a shared topic connection because the application will be ran in multiple instances (cluster).
The specs and the documentation says : "A non-durable shared subscription is used by a client which needs to be able to share the work of receiving messages from a topic subscription amongst multiple consumers. A non-durable shared subscription may therefore have more than one consumer. Each message from the subscription will be delivered to only one of the consumers on that subscription."
For me, all the clients using the same subscription name are in the same "cluster", only one client will receive a message at one time.
In my code, I've got an exception when the second client try to create the shared subscription. I really don't understand if this is a bug in MQ client libraries implementation or in my code. |
|
Back to top |
|
 |
TucoBouch |
Posted: Wed Feb 13, 2019 10:49 pm Post subject: |
|
|
Newbie
Joined: 13 Feb 2019 Posts: 2
|
Here my sample code :
Code: |
import javax.jms.JMSContext;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.Session;
import javax.jms.Topic;
import com.ibm.msg.client.jms.JmsConnectionFactory;
import com.ibm.msg.client.jms.JmsFactoryFactory;
import com.ibm.msg.client.wmq.WMQConstants;
public class TestGB {
public static void main(final String[] args) throws Exception {
MQTopicConnectionFactory cf = new MQTopicConnectionFactory();
cf.setHostName("xxx");
cf.setPort(1416);
cf.setQueueManager("xxx");
cf.setTransportType(WMQConstants.WMQ_CM_CLIENT);
cf.setChannel("xxx");
cf.setClientID("myClient");
Connection con = cf.createConnection();
for (int i = 0; i < 10; i++) {
new Thread(() -> {
try {
Session session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
con.start();
Topic topic = session.createTopic("TESTSUB/#");
MessageConsumer messageConsumer = session.createSharedConsumer(topic, "MYSUB");
System.out.println("Waiting for message...");
Message msg = messageConsumer.receive();
System.out.println("Received : \n" + msg);
}
catch (Exception ex) {
ex.printStackTrace();
}
}).start();
}
}
} |
The code below tries to create 10 threads consuming messages on the same topic. Only the first thread is able to connect, all the others fail with following exception :
Code: |
com.ibm.msg.client.jms.DetailedIllegalStateException: JMSWMQ0026: Failed to subscribe to topic 'TESTSUB' with selector 'none' using MQSUB.
There may have been a problem creating the subscription due to it being used by another message consumer.
Make sure any message consumers using this subscription are closed before trying to create a new subscription under the same name. Please see the linked exception for more information.
at com.ibm.msg.client.wmq.common.internal.Reason.reasonToException(Reason.java:472)
at com.ibm.msg.client.wmq.common.internal.Reason.createException(Reason.java:214)
at com.ibm.msg.client.wmq.internal.WMQMessageConsumer.checkJmqiCallSuccess(WMQMessageConsumer.java:212)
at com.ibm.msg.client.wmq.internal.WMQMessageConsumer.checkJmqiCallSuccess(WMQMessageConsumer.java:112)
at com.ibm.msg.client.wmq.internal.WMQConsumerShadow.initialize(WMQConsumerShadow.java:1038)
at com.ibm.msg.client.wmq.internal.WMQSyncConsumerShadow.initialize(WMQSyncConsumerShadow.java:134)
at com.ibm.msg.client.wmq.internal.WMQMessageConsumer.<init>(WMQMessageConsumer.java:470)
at com.ibm.msg.client.wmq.internal.WMQSession.createSharedConsumer(WMQSession.java:938)
at com.ibm.msg.client.jms.internal.JmsSessionImpl.createSharedConsumer(JmsSessionImpl.java:4228)
at com.ibm.msg.client.jms.internal.JmsSessionImpl.createSharedConsumer(JmsSessionImpl.java:4125)
at com.ibm.mq.jms.MQSession.createSharedConsumer(MQSession.java:1319)
at TestGB.lambda$0(TestGB.java:33)
at java.lang.Thread.run(Thread.java:748)
Caused by: com.ibm.mq.MQException: JMSCMQ0001: WebSphere MQ call failed with compcode '2' ('MQCC_FAILED') reason '2042' ('MQRC_OBJECT_IN_USE').
at com.ibm.msg.client.wmq.common.internal.Reason.createException(Reason.java:202)
... 11 more |
Tried with the last lib :
Code: |
<dependency>
<groupId>com.ibm.mq</groupId>
<artifactId>com.ibm.mq.allclient</artifactId>
<version>9.1.1.0</version>
</dependency> |
|
|
Back to top |
|
 |
fjb_saper |
Posted: Thu Feb 14, 2019 5:43 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Did you read this:
Quote: |
If a shared non-durable subscription already exists with the same name and client identifier (if set) but a different topic or message selector has been specified, and there is a consumer already active (i.e. not closed) on the subscription, then a JMSException will be thrown. |
 _________________ MQ & Broker admin |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|