示例:注册 WS-Notification 发布者

使用此任务以根据提供的示例代码摘录为订户客户机应用程序编写代码,以使用代理预订用户应用程序。

关于此任务

本示例的依据是,将 Java™ API for XML-based remote procedure calls (JAX-RPC) API 与使用 WSDL2Java 工具生成的代码(此代码针对创建 WS-Notification 服务点时生成的通知代理 WSDL 运行)以及 WebSphere® Application Server API 和 SPI 配合使用。

WebSphere Application Server 中,WS-Notification 服务有两个实现:V6.1 和 V7.0。此 JAX-RPC 示例可与 V6.1 或 V7.0 WS-Notification 服务点成功交互。 但是,如果要将 WS-Notification 与策略集配合使用(例如,启用与 WS-ReliableMessaging 的组合),那么 WS-Notification 应用程序必须编码为使用 Java API for XML-based Web Services (JAX-WS) 编程模型,并且必须与 V7.0 WS-Notification 服务点交互。 如果您不熟悉 JAX-WS 客户机应用程序编程,请参阅下列主题:

要为订户客户机应用程序编写可使用代理预订用户应用程序的代码,请完成以下步骤(参阅示例代码摘录以了解进一步信息)。

过程

  1. 查找 JAX-RPC 服务。 JNDI 名称特定于您的 Web Service 客户机信息。
  2. 获取要对其调用操作的端口的存根。
  3. 为要注册的发布者(生产者)创建引用。 这包含生产者 Web Service 的地址。
  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