String[] consumerEprs = null;
String subscriptionId = null;
WseMsgBrokerClient client = new WseMsgBrokerClient();
client.init(brokerLocation);
try {
consumerEprs = client.startConsumerService(consumerPort,
msgReciever);
} catch (MsgBrokerClientException e) {
e.printStackTrace();
System.out.println("unable to start consumer service, exiting");
return;
}
try {
subscriptionId = client.subscribe(consumerEprs[0], null,
xpathExpression);
System.out.println(getName() + "got the subscription id :"
+ subscriptionId);
} catch (MsgBrokerClientException e) {
e.printStackTrace();
System.out
.println("unable to subscribe for the xpath consumer exiting");
return;
}
try {
do {
SOAPEnvelope env = msgReciever.getQueue().take();
String msg;
try {
msg = env.getBody().getFirstElement().toStringWithConsume();
System.out.println(String.format(
"consumer [%s] recieved: %s", getName(), msg));
} catch (Exception e) {
System.err.print("invalid msg recieved");
}
} while (true);
} catch (InterruptedException ie) {
try {
// unsubscribe from the topic.
client.unSubscribe(subscriptionId);
} catch (MsgBrokerClientException e) {
e.printStackTrace();
System.out.println("unable to unsubscribe, ignoring");
}
// shutdown the consumer service.
client.shutdownConsumerService();
System.out.println("interrupted");
}