Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • Subscriber
  • Publisher
  • Subscription
  • Publishing request
  • Broker
  • PullPoint

The current implementation has several limitations:

  • subscriptions are not persistent: message will be lost if the subscriber can not be reached
  • subscriptions can not be clustered: if you register the same subscriber in a cluster, each node will receive all notifications
  • publishing can not be restricted to registered publishers: everyone can publish through an anonymous publisher

Usage scenarii

The WS-Notification SE can be used to provide publish/subscribe routing in the JBI bus. There are several usage:

Configuration using JBI packaging

The servicemix-wsn2005 accepts deployment of Service Units.
The SU must contain one or more files with an xml extension, each one containing a single WS-Notification request. The currently supported set of requests include:

The requests will be started in this very order, so that you can create a PullPoint and create a Subscription for it inside the same service unit.

Dynamic configuration inside the JBI bus

In addition to the deployment of service units, you can also create pull points or subscriptions dynamically from inside the JBI bus by using a simple API.

To create a subscription for a given JBI endpoint, you can use the following code:

Code Block
langjava

QName service = ...;
String endpoint = ...;
String topic = ...;
NotificationBroker wsnBroker = new NotificationBroker(getContext());
EndpointReferenceType consumer = new EndpointReferenceType();
consumer.setAddress(new AttributedURIType());
consumer.getAddress().setValue(service.getNamespaceURI() + "/" + service.getLocalPart() + "/" + endpoint);
wsnBroker.subscribe(consumer, topic);

To publish a message on a given topic:

Code Block
langjava

String topic = ...;
NotificationBroker wsnBroker = new NotificationBroker(getContext());
wsnBroker.notify(topic, message);

where message is a DOM element.

You can also create pull points and subscriptions for them:

Code Block
langjava

CreatePullPoint wsnCreatePullPoint = new CreatePullPoint(getContext());
PullPoint pullPoint = wsnCreatePullPoint.createPullPoint();
NotificationBroker wsnBroker = new NotificationBroker(getContext());
wsnBroker.subscribe(pullPoint.getEndpoint(), topic);

Later, you can pull notifications from this pull point:

Code Block
langjava

List<NotificationMessageHolderType> msgs = pullPoint.getMessages(0);

Outside the JBI bus

If you want to use WS-Notification ouside the JBI world, you will need to be able to receive incoming requests or send notifications to the external services. This must be done through by using Binding Components, either using HTTP or JMS.

To expose the NotificationBroker and CreatePullPoint services using HTTP/SOAP, you can deploy the following configuration file to servicemix-http:

Code Block
langxml

<beans xmlns:http="http://servicemix.apache.org/http/1.0"
       xmlns:wsn="http://servicemix.org/wsnotification">

  <http:endpoint service="wsn:NotificationBroker"
                 endpoint="http-binding"
                 targetService="wsn:NotificationBroker"
                 targetEndpoint="Broker"
                 role="consumer"
                 locationURI="http://localhost:8192/Broker/"
                 defaultMep="http://www.w3.org/2004/08/wsdl/in-out" 
                 soap="true"/>	               

  <http:endpoint service="wsn:CreatePullPoint"
                 endpoint="http-binding2"
                 targetService="wsn:CreatePullPoint"
                 targetEndpoint="Broker"
                 role="consumer"
                 locationURI="http://localhost:8192/CreatePullPoint/"
                 defaultMep="http://www.w3.org/2004/08/wsdl/in-out"
                 soap="true"/>

</beans>

Embedding WS-Notification

If you use a single static configuration file for ServiceMix, you can easily leverage this component to create subscription, pull-points and publish messages.

Code Block
langxml

  xmlns:sm="http://servicemix.apache.org/config/1.0"
  xmlns:wsn="http://servicemix.apache.org/wsn/1.0" 
  xmlns:test="http://servicemix.org/test"

<sm:activationSpec id="receiver" service="test:service" endpoint="endpoint">
  <sm:component>
    <bean class="org.apache.servicemix.tck.ReceiverComponent" />
  </sm:component>
</sm:activationSpec>

<sm:activationSpec>
  <sm:component>
    <wsn:component>
      <wsn:requests>
        <wsn:subscribe consumer="http://servicemix.org/test/service/endpoint" topic="myTopic" />
      </wsn:requests>
    </wsn:component>
  </sm:component>
</sm:activationSpec>

<sm:activationSpec service="test:publisher" endpoint="endpoint">
  <sm:component>
    <wsn:publisher topic="myTopic" />
  </sm:component>
</sm:activationSpec>

The above code snippet creates a publisher proxy, a subscription and a subscriber.

The publisher proxy is a simple component that wraps incoming JBI exchanges into WS-Notification notify requests and send them to a notification broker on the given topic. This could also be written in plain spring style:

Code Block
langxml

<sm:activationSpec service="test:publisher" endpoint="endpoint">
  <sm:component>
    <bean class="org.apache.servicemix.wsn.spring.PublisherComponent">
      <property name="topic" value="myTopic" />
    </bean>
  </sm:component>
</sm:activationSpec>

The subscription is created inside a servicemix-wsn2005 component. You must fill the consumer and topic properties, where the consumer is the URI-encoded target JBI endpoint, which will be resolved to the first component activated. You could also use the plain spring syntax:

Code Block
langxml

<sm:activationSpec>
  <sm:component>
    <bean class="org.apache.servicemix.wsn.spring.WSNSpringComponent">
      <property name="requests">
        <list>
          <bean class="org.apache.servicemix.wsn.spring.SubscribeFactoryBean">
            <property name="consumer" value="http://servicemix.org/test/service/endpoint" />
            <property name="topic" value="myTopic" />
          </bean>
        </list>
      </property>
    </bean>
  </sm:component>
</sm:activationSpec>

WS-Notification messages

Subscribe

Code Block
langxml

<wsnt:Subscribe
  xmlns:wsnt="http://docs.oasis-open.org/wsn/b-2"
  xmlns:wsa="http://www.w3.org/2005/08/addressing">
  <wsnt:ConsumerReference>
    <wsa:Address>
      http://www.consumer.org/service/endpoint
    </wsa:Address>
  </wsnt:ConsumerReference>
  <wsnt:Filter>
    <wsnt:TopicExpression Dialect="http://docs.oasis-open.org/wsn/t-1/TopicExpression/Simple">
      myTopic
    </wsnt:TopicExpression>
  </wsnt:Filter>
</wsnt:Subscribe>

CreatePullPoint

Code Block
langxml

<wsnt:CreatePullPoint 
  xmlns:wsnt="http://docs.oasis-open.org/wsn/b-2"
  xmlns:sm="http://servicemix.apache.org/wsn2005/1.0">
  <sm:address> 
    http://www.consumer.org/service/endpoint
  </sm:address>
</wsnt:CreatePullPoint>

Note that the <sm:address /> element is a ServiceMix extension that creates a PullPoint on a specific JBI endpoint. This is very useful when you want to create a subscription for this endpoint at deployment time (see the previous paragraph).

Wiki Markup
{scrollbar}