use of org.apache.cxf.wsn.client.NotificationBroker in project cxf by apache.
the class Client method main.
/**
* @param args
*/
public static void main(String[] args) throws Exception {
String wsnPort = "9000";
if (args.length > 0) {
wsnPort = args[0];
}
// Start a consumer that will listen for notification messages
// We'll just print the text content out for now.
Consumer consumer = new Consumer(new Consumer.Callback() {
public void notify(NotificationMessageHolderType message) {
Object o = message.getMessage().getAny();
System.out.println(message.getMessage().getAny());
if (o instanceof Element) {
System.out.println(((Element) o).getTextContent());
}
}
}, "http://localhost:9001/MyConsumer");
// Create a subscription for a Topic on the broker
NotificationBroker notificationBroker = new NotificationBroker("http://localhost:" + wsnPort + "/wsn/NotificationBroker");
Subscription subscription = notificationBroker.subscribe(consumer, "MyTopic");
// Send a notification on the Topic
notificationBroker.notify("MyTopic", new JAXBElement<String>(new QName("urn:test:org", "foo"), String.class, "Hello World!"));
// Just sleep for a bit to make sure the notification gets delivered
Thread.sleep(5000);
// Cleanup and exit
subscription.unsubscribe();
consumer.stop();
System.exit(0);
}
use of org.apache.cxf.wsn.client.NotificationBroker in project cxf by apache.
the class WsnBrokerTest method setUp.
@Before
public void setUp() throws Exception {
loader = Thread.currentThread().getContextClassLoader();
String impl = getProviderImpl();
Thread.currentThread().setContextClassLoader(new FakeClassLoader(impl));
WSNHelper.getInstance().setClassLoader(false);
System.setProperty("javax.xml.ws.spi.Provider", impl);
port2 = getFreePort();
if (!useExternal) {
port1 = getFreePort();
int brokerPort = getFreePort();
activemq = new ActiveMQConnectionFactory("vm:(broker:(tcp://localhost:" + brokerPort + ")?persistent=false)");
notificationBrokerServer = new JaxwsNotificationBroker("WSNotificationBroker", activemq);
notificationBrokerServer.setAddress("http://localhost:" + port1 + "/wsn/NotificationBroker");
notificationBrokerServer.init();
createPullPointServer = new JaxwsCreatePullPoint("CreatePullPoint", activemq);
createPullPointServer.setAddress("http://localhost:" + port1 + "/wsn/CreatePullPoint");
createPullPointServer.init();
}
notificationBroker = new NotificationBroker("http://localhost:" + port1 + "/wsn/NotificationBroker");
createPullPoint = new CreatePullPoint("http://localhost:" + port1 + "/wsn/CreatePullPoint");
}
Aggregations