BrokerClient bk = new BrokerClient();
bk.addServer("broker.bk.sapo.pt",3323);
bk.connect(); // if connection is not possible a runtime exception will be thrown
BrokerClient bk = new BrokerClient();
bk.addServer("broker.bk.sapo.pt",3323);
Future<HostInfo> f = bk.connectAsync();
f.get(); if connection is not possible a runtime exception will be thrown
BrokerClient bk = new BrokerClient();
// ... connecting ...
Future<HostInfo> f = bk.subscribe("/teste/",NetAction.DestinationType.QUEUE,new NotificationListenerAdapter() {
@Override
public boolean onMessage(NetNotification message, HostInfo host) {
// do something
return true; // return true or false to acknowledge or not
}
});
f.get(); //wait for subscription message to be sent
BrokerClient bk = new BrokerClient();
// ... connecting ...
while (true){
NetNotification notification = bk.poll("/teste/"); //blocks!!!
// ... do some work ...
bk.acknowledge(notification); //acknowledge the message
if( ... ){ // step out on some condition
break;
}
}
BrokerClient bk = new BrokerClient();
// ... connecting ...
long timeout = 5000;
while (true){
try{
NetNotification notification = bk.poll("/teste/",timeout); //blocks!!!
// ... do some work ...
bk.acknowledge(notification); //acknowledge the message
}catch (TimeoutException e){
// there was a timeout
}
if( ... ){ // step out on some condition
break;
}
}
BrokerClient bk = new BrokerClient();
// ... connecting ...
NetAction.DestinationType dstType = NetAction.DestinationType.QUEUE; // or TOPIC
Future<HostInfo> future = bk.publish("Olá Mundo", "/teste/", dstType);
UdpBrokerClient bk = new UdpBrokerClient();
bk.addServer("broker.bk.sapo.pt",3323);
NetAction.DestinationType dstType = NetAction.DestinationType.QUEUE; // or TOPIC
Future<HostInfo> future = bk.publish("Olá Mundo", "/teste/", dstType);