Exemple : inscription d'un diffuseur de publications WS-Notification
Utilisez cette tâche pour écrire le code requis par une application client de diffuseur de publications permettant d'inscrire une application client avec un courtier, sur la base du code fourni à titre d'exemple.
Pourquoi et quand exécuter cette tâche
Cet exemple repose sur l'utilisation des API JAX-RPC (Java™ API for XML-based remote procedure calls) avec le code généré en utilisant l'outil WSDL2Java (exécuté sur le WSDL Notification Broker généré par la création du point de service WS-Notification) et les API et SPI WebSphere Application Server.
Pour écrire le code requis par une application client de diffuseur de publications permettant d'inscrire une application client avec un courtier, exécutez les étapes ci-après en vous reportant au code fourni à titre d'exemple pour plus d'informations.
Procédure
Exemple
L'exemple de code suivant décrit un client JAX-RPC dans le rôle de l'inscription du diffuseur de publications, inscrivant l'application d'inscription d'un diffuseur de publications (fournisseur) avec un courtier.
// 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;