例: WS-Notification パブリッシャーの登録

このタスクは、示されているコード例の抜粋に基づいて、ブローカーを介してコンシューマー・アプリケーションをサブスクライブできるサブスクライバー・クライアント・アプリケーションのコードを作成する場合に使用します。

このタスクについて

この例は 、Java™ API for XML-based remote procedure calls (JAX-RPC) API と、WSDL2Java ツール (WS-Notification サービス・ポイントの作成の結果として生成された Notification Broker WSDL に対し実行) および WebSphere® Application Server API および SPI を使用して生成されたコードと併せた使用を基にしています。

WebSphere Application Server では、WS-Notification サービスにはバージョン 6.1 およびバージョン 7.0 の 2 つの実装があります。この JAX-RPC 例は、バージョン 6.1 またはバージョン 7.0 WS-Notification サービス・ポイントと正常にやり取りすることができます。 ただし、WS-Notification をポリシー・セットと一緒に使用したい場合は (例えば、WS-ReliableMessaging による構成を可能にするため)、Java API for XML-based Web Services (JAX-WS) プログラミング・モデルを使用するように WS-Notification アプリケーションをエンコードする必要があります。なおかつ WS-Notification アプリケーションはバージョン 7.0 WS-Notification サービス・ポイントとやり取りする必要があります。 JAX-WS クライアント・アプリケーションをプログラミングした経験がない場合は、以下のトピックを参照してください。

ブローカーを介してコンシューマー・アプリケーションをサブスクライブできるサブスクライバー・クライアント・アプリケーションのコードを作成するには、以下のステップを実行します (詳しくは、コード例の抜粋を参照)。

手順

  1. JAX-RPC サービスを検索します。 JNDI 名は、Web サービス・クライアントの実装に固有のものです。
  2. 操作の呼び出しを行うポートのスタブを取得します。
  3. 登録するパブリッシャー (プロデューサー) の参照を作成します。 これには、プロデューサーの Web サービスのアドレスが含まれます。
  4. プロデューサーがメッセージを公開するトピックを記述するためのトピック式のリスト (配列) を作成します。
  5. パブリッシャーが要求ベースの公開を使用しないように指示します。
  6. 登録の初期終了時刻の値を設定します。 例えば、今から 1 年後という値を設定することができます。
  7. ブローカーから返される以下の複数の値を保持するためのホルダーを作成します。
    • PublisherRegistrationReference。登録の存続時間の管理で使用されるエンドポイント参照を定義します。
    • ConsumerReference。メッセージの後続の公開で使用されるエンドポイント参照を定義します。
  8. スタブで関連付けられているメソッドを呼び出して、RegisterPublisher 操作を呼び出します。
  9. PublisherRegistrationReference を取得します。
  10. ConsumerReference を取得します。

以下のコード例は、パブリッシャー登録ロールを果たす JAX-RPC クライアントが、パブリッシャー (プロデューサー) アプリケーションをブローカーに登録することを示しています。

// Look up the JAX-RPC service. The JNDI name is specific to your web services client implementation
InitialContext context = new InitialContext();
javax.xml.rpc.Service service = (javax.xml.rpc.Service) context.lookup(
    "java:comp/env/services/NotificationBroker");

// Get a stub for the port on which you want to invoke operations
NotificationBroker stub = (NotificationBroker) service.getPort(NotificationBroker.class);

// Create a reference for the publisher (producer) being registered. This contains the address of the
// producer Web service.
EndpointReference publisherEPR = 
    EndpointReferenceManager.createEndpointReference(new URI("http://myserver.mysom.com:9080/Producer"));

// Create a list (array) of topic expressions to describe the topics to which the producer publishes
// messages. For this example you add one topic
Map prefixMappings = new HashMap();
prefixMappings.put("abc", "uri:mytopicns");
TopicExpression topic = 
    new TopicExpression(TopicExpression.SIMPLE_TOPIC_EXPRESSION, "abc:xyz", prefixMappings);                
TopicExpression[] topics = new TopicExpression[] {topic};

// Indicate that you do not want the publisher to use demand based publishing
Boolean demand = Boolean.FALSE;

// Set a value for the initial termination time of the registration. For example, set a value 1 year in
// the future
Calendar initialTerminationTime = Calendar.getInstance();
initialTerminationTime.add(Calendar.YEAR, 1);

// Create holders to hold the multiple values returned from the broker:
// PublisherRegistrationReference: An endpoint reference for use in lifetime management of
// the registration
EndpointReferenceTypeHolder pubRegMgrEPR = new EndpointReferenceTypeHolder();

// ConsumerReference: An endpoint reference for use in subsequent publishing of messages
EndpointReferenceTypeHolder consEPR = new EndpointReferenceTypeHolder();

// Invoke the RegisterPublisher operation by calling the associated method on the stub
stub.registerPublisher(publisherEPR, topics, demand, initialTerminationTime, null, pubRegMgrEPR, consEPR);

// Retrieve the PublisherRegistrationReference
EndpointReference registrationEPR = pubRegMgrEPR.value;

// Retrieve the ConsumerReference
EndpointReference consumerReferenceEPR = consEPR.value;

トピックのタイプを示すアイコン タスク・トピック



タイム・スタンプ・アイコン 最終更新: last_date
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=cord&product=was-nd-mp&topic=tjwsn_ex_pub_reg
ファイル名:tjwsn_ex_pub_reg.html