共有サブスクリプション
WebSphere® Application Server バージョン 9.0 は、永続サブスクリプションと非永続サブスクリプションのどちらの共有もサポートします。JMS 2.0 仕様で導入された共有サブスクリプションは、単一のサブスクリプションを複数のコンシューマーで共有するために使用されます。どの時点においても、パブリケーションを受け取るコンシューマーは 1 人だけです。共有サブスクリプションは、基本的に、負荷を複数のコンシューマー間で共有するために使用され、名前とクライアント ID によって識別されます。
共有非永続および共有永続サブスクリプションについて詳しくは、JMS 2.0 仕様文書のセクション 8.3.2 および 8.3.4 を参照してください。
注: 共有永続サブスクリプション・フィーチャーは、以前のバージョンの WebSphere Application Serverで使用可能でした。また、共有非永続サブスクリプション・フィーチャーは、WebSphere Application Server バージョン 9.0 で導入されました。
次の例は、共有永続サブスクリプションおよび共有非永続サブスクリプションを作成するコード・サンプルを示しています。
共有永続サブスクリプションの作成
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);
共有非永続サブスクリプションの作成
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);
注: 以下の選択基準を使用して、共有永続および共有非永続サブスクリプションを作成できます。
consumer = session.createSharedConsumer(topic, sharedSubName, selector);
consumer = session.createSharedDurableConsumer(topic, sharedDurableSubName, selector);