Notification Support

Key
This line was removed.
This word was removed. This word was added.
This line was added.

Changes (3)

View Page History
}{code}

There are also some simple Java clients available to ease the developer life.  life:
{code:language=java}package org.petalslink.dsb.notification.client.http;

import javax.xml.namespace.QName;

import junit.framework.TestCase;

import org.petalslink.dsb.notification.client.http.simple.HTTPConsumerClient;
import org.petalslink.dsb.notification.client.http.simple.HTTPProducerClient;
import org.petalslink.dsb.notification.client.http.simple.HTTPSubscriptionManagerClient;
import org.w3c.dom.Document;

import com.ebmwebsourcing.easycommons.xml.XMLHelper;
import com.ebmwebsourcing.wsstar.basefaults.datatypes.impl.impl.WsrfbfModelFactoryImpl;
import com.ebmwebsourcing.wsstar.basenotification.datatypes.impl.impl.WsnbModelFactoryImpl;
import com.ebmwebsourcing.wsstar.resource.datatypes.impl.impl.WsrfrModelFactoryImpl;
import com.ebmwebsourcing.wsstar.resourcelifetime.datatypes.impl.impl.WsrfrlModelFactoryImpl;
import com.ebmwebsourcing.wsstar.resourceproperties.datatypes.impl.impl.WsrfrpModelFactoryImpl;
import com.ebmwebsourcing.wsstar.topics.datatypes.impl.impl.WstopModelFactoryImpl;
import com.ebmwebsourcing.wsstar.wsnb.services.impl.util.Wsnb4ServUtils;

/**
* @author chamerling
*
*/
public class DSBTest extends TestCase {

public void testSubscribeNotifyUnsubscribe() throws Exception {
Wsnb4ServUtils.initModelFactories(new WsrfbfModelFactoryImpl(),
new WsrfrModelFactoryImpl(), new WsrfrlModelFactoryImpl(),
new WsrfrpModelFactoryImpl(), new WstopModelFactoryImpl(),
new WsnbModelFactoryImpl());

String dsb = "http://localhost:8084/petals/services/NotificationProducerPortService";
String subscriber = "http://localhost:9000/services/RawService";

// subscribe. Notifications will be sent to subscriber endpoint.
System.out.println("Subscribe");
HTTPProducerClient producerClient = new HTTPProducerClient(dsb);
String namespaceURI = "http://streams.event-processing.org/ids/";
String localPart = "NiceTempStream";
String prefix = "s";

QName topic = new QName(namespaceURI, localPart, prefix);
String UUID = producerClient.subscribe(topic, subscriber);
System.out.println("UUID : " + UUID);

// notify directly to the DSB. Up to the DSB to route messages to the
// right subscribers
System.out.println("Notify...");
Document payload = XMLHelper.createDocumentFromString("<foo>123456789</foo>");
HTTPConsumerClient consumerClient = new HTTPConsumerClient(
"http://localhost:8084/petals/services/NotificationConsumerPortService");
consumerClient.notify(payload, topic);

// Unsubscribe. We need the original subscription UUID!
System.out.println("Unsubscribe...");
HTTPSubscriptionManagerClient subscriptionManagerClient = new HTTPSubscriptionManagerClient(
dsb);
subscriptionManagerClient.unsubscribe(UUID);

// Notify on the same topic : Notifications are no more delivered to the
// original subscriber.
System.out.println("Notify...");
payload = XMLHelper.createDocumentFromString("<foo>AFTER</foo>");

for (int i = 0; i < 10; i++) {
System.out.println("Notify #" + i);
consumerClient.notify(payload, topic);
Thread.sleep(2000);
}
}
}{code}

h1. Configuration