public static void main(String[] args) throws Exception {
QueueConnection conn = null;
QueueSession session = null;
//TODO Don't do this FakeJndi stuff once we have remote JNDI working
DeploymentUtils utils = null;
try {
utils = new DeploymentUtils("fakejndi.sar", FakeJndi.class.getPackage());
utils.deploy();
QueueConnectionFactory qcf = lookup(utils, "RemoteConnectionFactory", QueueConnectionFactory.class);
Queue queue = lookup(utils, "queue/test", Queue.class);
System.out.println("Got qcf " + qcf);
System.out.println("Got q " + queue);
conn = qcf.createQueueConnection();
conn.start();
session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
// Set the async listener
QueueReceiver recv = session.createReceiver(queue);
recv.setMessageListener(new MessageListener() {
@Override
public void onMessage(Message message) {
TextMessage msg = (TextMessage)message;
try {
System.out.println("---->Received: " + msg.getText());
} catch (JMSException e) {
e.printStackTrace();
}
}
});
QueueSender sender = session.createSender(queue);
for (int i = 0 ; i < 10 ; i++) {
String s = "Test" + i;
System.out.println("----> Sending: " +s );
TextMessage msg = session.createTextMessage(s);
sender.send(msg);
}
Thread.sleep(1000);
} finally {
try {
conn.stop();
} catch (Exception ignore) {
}
try {
session.close();
} catch (Exception ignore) {
}
try {
conn.close();
} catch (Exception ignore) {
}
utils.undeploy();
safeClose(utils);
}
}