This code below creates JMS queue at run time in Wildfly 9.0.1 with no problem. In Wildfly 10 and 11 hornetq-server was replaced with activemq. How properly migrate it to Wildfly 10/11? Thank you.
private boolean createQueue(String operationName, String queueName) {
boolean result = false;
ModelControllerClient client = qService.getModelControllerClient();
if(client != null){
ModelNode operation = new ModelNode();
ModelNode address = operation.get(ClientConstants.OP_ADDR);
address.add("subsystem", "messaging");
address.add("hornetq-server", "default");
address.add("jms-queue", queueName);
ModelNode entries = operation.get("entries");
entries.add("jms/queue/" + queueName);
operation.get(ClientConstants.OP).set(operationName);
try {
ModelNode returnVal = client.execute(operation);
return returnVal.get("outcome").asString().equalsIgnoreCase("success");
} catch (Exception e) {
DLOG.error(ExceptionUtils.getStackTrace(e));
} finally {
try {
client.close();
} catch (IOException ex) {
DLOG.error(ExceptionUtils.getStackTrace(ex));
}
}
}
return result;
}
With Wildfly 10 the JMS-Implementation changed from HornetQ to Apache ActiveMQ Artemis.The following example is tested with Wildfly 10.
You could prepare the command to create a queue like this:
And execute the operation with this method:
The code runs inside a WAR with the following maven dependency:
With Java EE 7 and JMS 2.0 there is as well the annotation @JMSDestinationDefinitions which allows automatic creation of JMS resources at deployment time. For some use cases this could already be good enough.