private ManagementClient managementClient;
@Test
public void testMessagingClient() throws Exception {
QueueConnection conn = null;
QueueSession session = null;
ModelControllerClient client = managementClient.getControllerClient();
boolean actionsApplied = false;
try {
// Create the queue using the management API
ModelNode op = new ModelNode();
op.get("operation").set("add");
op.get("address").add("subsystem", "messaging");
op.get("address").add("hornetq-server", "default");
op.get("address").add("jms-queue", QUEUE_NAME);
op.get("entries").add(EXPORTED_QUEUE_NAME);
applyUpdate(op, client);
actionsApplied = true;
QueueConnectionFactory qcf = (QueueConnectionFactory) remoteContext.lookup("jms/RemoteConnectionFactory");
Queue queue = (Queue) remoteContext.lookup(QUEUE_NAME);
conn = qcf.createQueueConnection("guest", "guest");
conn.start();
session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
final CountDownLatch latch = new CountDownLatch(10);
final List<String> result = new ArrayList<String>();
// Set the async listener
QueueReceiver recv = session.createReceiver(queue);
recv.setMessageListener(new MessageListener() {
@Override
public void onMessage(Message message) {
TextMessage msg = (TextMessage)message;
try {
result.add(msg.getText());
latch.countDown();
} catch (JMSException e) {
e.printStackTrace();
}
}
});
QueueSender sender = session.createSender(queue);
for (int i = 0 ; i < 10 ; i++) {
String s = "Test" + i;
TextMessage msg = session.createTextMessage(s);
sender.send(msg);
}
Assert.assertTrue(latch.await(3, TimeUnit.SECONDS));
Assert.assertEquals(10, result.size());
for (int i = 0 ; i < result.size() ; i++) {
Assert.assertEquals("Test" + i, result.get(i));
}
} finally {
try {
conn.stop();
} catch (Exception ignore) {
}
try {
session.close();
} catch (Exception ignore) {
}
try {
conn.close();
} catch (Exception ignore) {