final ModelControllerClient client = ModelControllerClient.Factory.create(InetAddress.getByName("localhost"), 9999, DemoAuthentication.getCallbackHandler());
try {
// Check that the queue does not exist
if(queueExists(queueName, sf)) {
throw new IllegalStateException();
}
// Create a new core queue using the standalone client
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("queue", queueName);
op.get("queue-address").set(queueName);
applyUpdate(op, client);
// Check if the queue exists
if(! queueExists(queueName, sf)) {
throw new IllegalStateException();
}
ClientSession session = null;
try {
session = sf.createSession();
ClientProducer producer = session.createProducer(queueName);
ClientMessage message = session.createMessage(false);
final String propName = "myprop";
message.putStringProperty(propName, "Hello sent at " + new Date());
System.out.println("Sending the message.");
producer.send(message);
ClientConsumer messageConsumer = session.createConsumer(queueName);
session.start();
ClientMessage messageReceived = messageConsumer.receive(1000);
System.out.println("Received TextMessage:" + messageReceived.getStringProperty(propName));
} finally {
if (session != null) {
session.close();
}
}
op = new ModelNode();
op.get("operation").set("remove");
op.get("address").add("subsystem", "messaging");
op.get("address").add("hornetq-server", "default");
op.get("address").add("queue", queueName);
applyUpdate(op, client);
// Check that the queue does not exist
if(queueExists(queueName, sf)) {
throw new IllegalStateException();
}
} finally {
client.close();
}
}