public static void main(String[] args) throws Exception {
QueueConnection conn = null;
QueueSession session = null;
ModelControllerClient client = ModelControllerClient.Factory.create(InetAddress.getByName("localhost"), 9999);
//TODO Don't do this FakeJndi stuff once we have remote JNDI working
DeploymentUtils utils = null;
boolean actionsApplied = false;
try {
utils = new DeploymentUtils("fakejndi.sar", FakeJndi.class.getPackage());
utils.deploy();
ModelNode op = new ModelNode();
op.get("operation").set("add");
op.get("address").add("subsystem", "jms");
op.get("address").add("queue", QUEUE_NAME);
op.get("entries").add(QUEUE_NAME);
applyUpdate(op, client);
actionsApplied = true;
QueueConnectionFactory qcf = lookup(utils, "RemoteConnectionFactory", QueueConnectionFactory.class);
Queue queue = lookup(utils, QUEUE_NAME, Queue.class);
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) {
}
if(utils != null) {
utils.undeploy();
}
safeClose(utils);
if(actionsApplied) {
// Remove the queue using the management API
ModelNode op = new ModelNode();