wsnPort = args[0];
}
// Start a consumer that will listen for notification messages
// We'll print the email fields out.
Consumer consumer = new Consumer(new Consumer.Callback() {
public void notify(NotificationMessageHolderType message) {
Object o = message.getMessage().getAny();
if (o instanceof Element) {
Element e = (Element)o;
System.out.println();
System.out.println("From: "+e.getElementsByTagNameNS(mailNs,"from").item(0).getTextContent());
System.out.println("To: "+e.getElementsByTagNameNS(mailNs,"to").item(0).getTextContent());
System.out.println("Subject: "+e.getElementsByTagNameNS(mailNs,"subject").item(0).getTextContent());
System.out.println("Body: "+e.getElementsByTagNameNS(mailNs,"body").item(0).getTextContent());
System.out.println();
}else {
System.out.println(o);
}
}
}, "http://localhost:9001/MyConsumer");
// Create a subscription for a Topic on the broker
NotificationBroker notificationBroker
= new NotificationBroker("http://localhost:" + wsnPort + "/wsn/NotificationBroker",Email.class);
Subscription subscription = notificationBroker.subscribe(consumer, topic);
// Create new email object to send
Email mail = new Email("standalone@client.com","you@gotmail.com","This is the standalone client speaking","This thing works!");
// Send a notification on the Topic
notificationBroker.notify(topic,mail);
// 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);
}