+

Search Tips   |   Advanced Search

Example: Registering a WS-Notification publisher

Use this task to write the code for a subscriber client application that can subscribe a consumer application with a broker, based on the example code extract provided.

This example is based on using the Java API for XML-based remote procedure calls (JAX-RPC) APIs with code generated using the WSDL2Java tool (run against the Notification Broker WSDL generated as a result of creating the WS-Notification service point) and WebSphere Application Server APIs and SPIs.

In WebSphere Application Server there are two implementations of the WS-Notification service: Version 6.1 and Version 7.0. This JAX-RPC example can interact successfully with Version 6.1 or Version 7.0 WS-Notification service points. However to use WS-Notification with policy sets, for example to enable composition with WS-ReliableMessaging, then the WS-Notification applications must be encoded to use the Java API for XML-based Web Services (JAX-WS) programming model and must interact with Version 7.0 WS-Notification service points. If we are new to programming JAX-WS client applications, see the following topics:

To write the code for a subscriber client application that can subscribe a consumer application with a broker, complete the following steps, referring to the example code extract for further information.

  1. Look up the JAX-RPC service. The JNDI name is specific to the web services client implementation.

  2. Get a stub for the port on which to invoke operations.

  3. Create a reference for the publisher (producer) being registered. This contains the address of the producer web service.

  4. Create a list (array) of topic expressions to describe the topics to which the producer publishes messages.

  5. Indicate that we do not want the publisher to use demand based publishing.

  6. Set a value for the initial termination time of the registration. For example, you could set a value 1 year in the future.

  7. Create holders to hold the multiple values returned from the broker:

    • PublisherRegistrationReference defines the endpoint reference for use in lifetime management of the registration.

    • ConsumerReference defines the endpoint reference for use in subsequent publishing of messages.

  8. Invoke the RegisterPublisher operation by calling the associated method on the stub.

  9. Retrieve the PublisherRegistrationReference.

  10. Retrieve the ConsumerReference.


Example

The following example code represents a JAX-RPC client acting in the publisher registration role, registering a publisher (producer) application with a broker.

// Look up the JAX-RPC service. The JNDI name is specific to the 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 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 we 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 we 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;


Related concepts

  • JAX-RPC
  • Brokered notification

  • JAX-RPC

  • Brokered notification

  • WS-Notification


    Related tasks

  • Writing a WS-Notification application that exposes a web service endpoint

  • Writing a WS-Notification application that does not expose a web service endpoint

  • Filtering the message content of publications

  • Example: Subscribing a WS-Notification consumer

  • Example: Pausing a WS-Notification subscription

  • Example: Publishing a WS-Notification message

  • Example: Create a WS-Notification pull point

  • Example: Getting messages from a WS-Notification pull point

  • Example: Create a Notification consumer web service skeleton

  • Use WS-Notification for publish and subscribe messaging for web services

  • Secure WS-Notification

  • WSDL2Java command for JAX-RPC applications

  • WSDL2Java command for JAX-RPC applications

  • WS-Notification troubleshooting tips

  • Writing JAX-WS applications for WS-Notification

  • WS-BrokeredNotification Version 1.3 OASIS Standard
    WS-BrokeredNotification Version 1.3 OASIS Standard
    Writing JAX-WS applications for WS-Notification