Shared subscriptions
WebSphere Application Server version 9.0 supports sharing of both durable and nondurable subscriptions. Shared subscription, which is introduced in JMS 2.0 specification, is used to share a single subscription among multiple consumers, with only one of the consumers receiving a publication at any point in time. Shared subscriptions are basically used for sharing the load among multiple consumers, and are identified by the name and client identifier.
For more information about shared nondurable and durable subscriptions, refer to the sections 8.3.2 and 8.3.4 in the JMS 2.0 specification document.
Shared durable subscription feature was available in the earlier versions of WAS, and shared nondurable subscription feature is introduced in WAS version 9.0.
The following example shows the code sample of creating a shared durable and shared nondurable subscription:
Create a shared durable subscription
ConnectionFactory connectionFactory; Connection connection; Session session; MessageConsumer consumer; Topic topic; String sharedDurableSubName; ... connection = connectionFactory.createConnection(); // Note: client ID is not mandatory for shared durable subscriptions connection.setClientID("myClient"); session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); topic = session.createTopic("sharedTopic"); consumer = ((ImaSubscription)session).createSharedDurableConsumer(topic, sharedDurableSubName);
Create a shared non-durable subscription
ConnectionFactory connectionFactory; Connection connection; Session session; MessageConsumer consumer; Topic topic; String sharedSubName; ... connection = connectionFactory.createConnection(); connection.setClientID("myClient"); session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); topic = session.createTopic("sharedTopic"); consumer = ((ImaSubscription)session).createSharedConsumer(topic, sharedSubName);Shared durable and shared non-durable subscription can be created using the following selection criteria:
consumer = session.createSharedConsumer(topic, sharedSubName, selector); consumer = session.createSharedDurableConsumer(topic, sharedDurableSubName, selector);
Configure shared durable subscriptions for a connection factory Configure shared non-durable subscriptions for a connection factory