如何在Wildfly 10/11的运行时以编程方式添加jms队列?

如何在Wildfly 10/11的运行时以编程方式添加jms队列?,jms,wildfly-10,wildfly-11,Jms,Wildfly 10,Wildfly 11,下面的代码在运行时在Wildfly 9.0.1中创建JMS队列,没有问题。在Wildfly 10和11中,hornetq服务器被activemq取代。如何正确地将其迁移到Wildfly 10/11? 多谢各位 private boolean createQueue(String operationName, String queueName) { boolean result = false; ModelControllerClient client = qServic

下面的代码在运行时在Wildfly 9.0.1中创建JMS队列,没有问题。在Wildfly 10和11中,hornetq服务器被activemq取代。如何正确地将其迁移到Wildfly 10/11? 多谢各位

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;
}

使用Wildfly 10,JMS实现从HornetQ更改为ApacheActiveMQ Artemis

您可以准备命令以创建如下队列:

public void createQueue() throws Exception {
    ModelControllerClient client = ModelControllerClient.Factory.create(InetAddress.getByName("localhost"), 9990);
    if (client != null) {
        ModelNode op = new ModelNode();
        op.get(ClientConstants.OP_ADDR).add(ClientConstants.SUBSYSTEM, "messaging-activemq");
        op.get(ClientConstants.OP_ADDR).add(ClientConstants.SERVER, "default");
        op.get(ClientConstants.OP_ADDR).add("jms-queue", "HelloWorldQueue");
        op.get("entries").add("queue/HelloWorldQueue");
        op.get("entries").add("java:jboss/exported/queue/HelloWorldQueue");
        op.get(ClientConstants.OP).set("add");
        applyUpdate(op, client);
    }
}
并使用此方法执行操作:

private static void applyUpdate(ModelNode update, final ModelControllerClient client) throws IOException {
    LOG.info("Execute: " + update.toString());
    ModelNode result = client.execute(new OperationBuilder(update).build());
    if (result.hasDefined("outcome") && "success".equals(result.get("outcome").asString())) {
        if (result.hasDefined("result")) {
            LOG.info(result.get("result").toString());
        }
    } else if (result.hasDefined("failure-description")) {
        throw new RuntimeException(result.get("failure-description").toString());
    } else {
        throw new RuntimeException("Operation not successful; outcome = " + result.get("outcome"));
    }
}
代码在具有以下maven依赖项的WAR中运行:

<dependency>
    <groupId>org.wildfly.core</groupId>
    <artifactId>wildfly-controller-client</artifactId>
    <version>3.0.10.Final</version>
</dependency>

org.wildfly.core
它允许在部署时自动创建JMS资源。对于某些用例,这已经足够好了