Wildfly-Swarm并通过资源适配器连接到外部activemq:WFLYCTL0412 [英] Wildfly-Swarm and connection to external activemq via resource adapter: WFLYCTL0412

查看:111
本文介绍了Wildfly-Swarm并通过资源适配器连接到外部activemq:WFLYCTL0412的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我已经花了很多时间,但是现在我完全处于机智...

So I've already spent considerable time on this, but now have come to a point where I'm completely at my wits end...


我正在尝试将基于Wildfly 10.1.0的消息驱动Bean连接到外部activemq 5.15.0服务器(旧 activemq,而不是artemis mq!)。
为此,我正在部署资源适配器并调整配置。
在标准配置的wildfly中可以正常工作。我正在使用以下脚本来设置容器:

The requirement: I'm trying to connect a wildfly 10.1.0 based message driven bean to an external activemq 5.15.0 server (the 'old' activemq, not artemis mq!). For this I'm deploying the resource adapter and tweaking the configuration. In standard deployment of wildfly this works ok. I'm using the following script to setup the container:

# Disable the artemis messaging completely
/subsystem=messaging-activemq/server=default:remove

# Deploy the resource adapter
deploy ${project.build.directory}/activemq-rar-5.15.0.rar

/subsystem=resource-adapters/resource-adapter=activemq-rar.rar:add(archive=activemq-rar-5.15.0.rar,transaction-support=LocalTransaction)
/subsystem=resource-adapters/resource-adapter=activemq-rar.rar/config-properties=ServerUrl:add(value="${activemq.broker}")
/subsystem=resource-adapters/resource-adapter=activemq-rar.rar/config-properties=UserName:add(value="${jboss.user}")
/subsystem=resource-adapters/resource-adapter=activemq-rar.rar/config-properties=Password:add(value="${jboss.password}")
/subsystem=resource-adapters/resource-adapter=activemq-rar.rar/config-properties=UseInboundSession:add(value="false")
/subsystem=resource-adapters/resource-adapter=activemq-rar.rar/connection-definitions=AMQConnectionFactory:add(jndi-name=ConnectionFactory,class-name=org.apache.activemq.ra.ActiveMQManagedConnectionFactory,enabled=true,min-pool-size=1,max-pool-size=20,pool-prefill=false,same-rm-override=false,use-java-context=true)
/subsystem=resource-adapters/resource-adapter=activemq-rar.rar/admin-objects=REQUESTQUEUE:add(class-name=org.apache.activemq.command.ActiveMQQueue,jndi-name=queues/request,use-java-context=true)
/subsystem=resource-adapters/resource-adapter=activemq-rar.rar/admin-objects=REPLYQUEUE:add(class-name=org.apache.activemq.command.ActiveMQQueue,jndi-name=queues/reply,use-java-context=true)
/subsystem=ejb3:write-attribute(name=default-resource-adapter-name,value=activemq-rar.rar)
/subsystem=ejb3:write-attribute(name=default-mdb-instance-pool,value=mdb-strict-max-pool)
/subsystem=ee/service=default-bindings:write-attribute(name=jms-connection-factory,value=java:/ConnectionFactory)

reload

通过此配置,我可以使用独立完整配置启动容器(也可以获取与JMS相关的类),并且可以按预期工作。

With this configuration I can launch the container with the standalone-full configuration (to get the JMS related classes as well) and it works as intended.

但是,如果我尝试使用wildfly swarm实现相同的功能,则无法部署相同的测试mdb.jar,在容器启动期间,我会收到以下异常:

But if I attempt to achieve the same with wildfly swarm, the same test mdb.jar cannot be deployed, during startup of the container I get the following exception:

"WFLYCTL0412: Required services that are not installed:" => ["jboss.ra.activemq-rar"],
"WFLYCTL0180: Services with missing/unavailable dependencies" => ["jboss.deployment.unit.\"mdbtest.jar\".component.TestMDB.CREATE is missing [jboss.ra.activemq-rar]"]

似乎资源适配器不可用,但是在我部署的管理控制台中也可以看到。

So it seems, that the resource adapter is not available, however it is visible in the administration console I deployed as well.

要设置群集容器,请使用以下project-defaults.xml:

To setup the swarm container I use the following project-defaults.xml:

swarm:

  resource-adapters:
    resource-adapters:
      activemq-rar:
        archive: activemq-rar-15.5.0.rar
        transaction-support: LocalTransaction
        config-properties:
          ServerUrl:
            value: failover:tcp://localhost:61616
          UserName:
            value: admin
          Password:
            value: admin
          UseInboundSession:
            value: false

        connection-definitions:
            AMQConnectionFactory:
                jndi-name: ConnectionFactory
                class-name: org.apache.activemq.ra.ActiveMQManagedConnectionFactory
                enabled: true
                min-pool-size: 1
                max-pool-size: 20
                pool-prefill: false
                same-rm-override: false
                use-java-context: true
                same-rm-override: false

        admin-objects:
            REQUESTQUEUE:
                class-name: org.apache.activemq.command.ActiveMQQueue
                jndi-name: queues/request
                use-java-context: true
            REPLEYQUEUE:
                class-name: org.apache.activemq.command.ActiveMQQueue
                jndi-name: queues/reply
                use-java-context: true

  ejb3:
    # Switch the MDB default to the resource adapter defined above
    default-resource-adapter-name: activemq-rar
    default-mdb-instance-pool: mdb-strict-max-pool

  ee:
      default-bindings:
          jms-connection-factory: java:/ConnectionFactory


  management:
    security-realms:
      ManagementRealm:
        in-memory-authentication:
          users:
            admin:    
              password: admin                            
    http-interface-management-interface:
      allowed-origins:
      - http://localhost:8080
      security-realm: ManagementRealm

  messaging-activemq:
    servers:
      default:
#        active: false
#        connection-factories:
#          InVmConnectionFactory:
#            client-id: blahblabla
#            block-on-acknowledge: true
#            entries:
#            - "java:/ArtemisConnectionFactory"
#        pooled-connection-factories:
#          activemq-ra:
#            entries:
#            connectors: in-vm
#            transaction: xa

  jca:
    archive-validation:
      enabled: false


  datasources:
    jdbc-drivers:
      org.postgresql:
        driver-class-name: org.postgresql.Driver
        xa-datasource-class-name: org.postgresql.xa.PGXADataSource
        driver-module-name: org.postgresql

    data-sources:
      myDS:
        connection-url: jdbc:postgresql://localhost:5432/mydb
        user-name: dbuser
        password: dbpassword
        driver-name: postgresql
        jndi-name: java:jboss/datasources/myDS
        min-pool-size: 4
        max-pool-size: 64
        use-ccm: false


  deployment:
    org.apache.activemq:activemq-rar.rar:
    com.oneworldsync.mdb:mdbtest.jar:
    org.postgresql:postgresql.jar:

  logging:
    loggers:
      org.jboss:
        level: warn
      org.wildfly:
        level: warn

pom的相关部分如下所示:

The relevant part of the pom looks like this:

<build>
  <plugins>
    <plugin>
      <groupId>org.wildfly.swarm</groupId>
      <artifactId>wildfly-swarm-plugin</artifactId> 
      <version>2017.4.0</version>
      <executions>
        <execution>
          <id>package</id>
          <goals>
            <goal>package</goal>
          </goals>
          <phase>package</phase>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>


<dependencies>
  <dependency>
    <groupId>com.oneworldsync.mdb</groupId>
    <artifactId>mdbtest</artifactId>
    <version>1.0.0-SNAPSHOT</version>
  </dependency>
  <dependency>
    <groupId>org.wildfly.swarm</groupId>
    <artifactId>logging</artifactId>
  </dependency>
  <dependency>
    <groupId>org.wildfly.swarm</groupId>
    <artifactId>datasources</artifactId>
  </dependency>
  <dependency>
    <groupId>org.wildfly.swarm</groupId>
    <artifactId>undertow</artifactId>
  </dependency>
  <dependency>
    <groupId>org.postgresql</groupId>
    <artifactId>postgresql</artifactId>
    <version>42.1.4</version>
  </dependency>
  <dependency>
    <groupId>org.wildfly.swarm</groupId>
    <artifactId>cdi</artifactId>
  </dependency>
  <dependency>
    <groupId>org.wildfly.swarm</groupId>
    <artifactId>jpa</artifactId>
  </dependency>
  <dependency>
    <groupId>org.wildfly.swarm</groupId>
    <artifactId>msc</artifactId>
  </dependency>
  <dependency>
    <groupId>org.wildfly.swarm</groupId>
    <artifactId>infinispan</artifactId>
  </dependency>
  <dependency>
    <groupId>org.wildfly.swarm</groupId>
    <artifactId>messaging</artifactId>
  </dependency>
  <dependency>
    <groupId>org.wildfly.swarm</groupId>
    <artifactId>jca</artifactId>
  </dependency>
  <dependency>
    <groupId>org.wildfly.swarm</groupId>
    <artifactId>resource-adapters</artifactId>
  </dependency>
  <dependency>
    <groupId>org.apache.activemq</groupId>
    <artifactId>activemq-rar</artifactId>
    <version>${activemq.version}</version>
    <type>rar</type>
  </dependency>
  <dependency>
    <groupId>org.wildfly.swarm</groupId>
    <artifactId>management</artifactId>
  </dependency>
  <dependency>
    <groupId>org.wildfly.swarm</groupId>
    <artifactId>management-console</artifactId>
  </dependency>
  <dependency>
    <groupId>org.wildfly.swarm</groupId>
    <artifactId>cli</artifactId>
    <version>${jboss.version}</version>
  </dependency>
  <dependency>
    <groupId>org.wildfly.swarm</groupId>
    <artifactId>ejb</artifactId>
  </dependency>
  <dependency>
    <groupId>org.wildfly.swarm</groupId>
    <artifactId>connector</artifactId>
  </dependency>
  <dependency>
    <groupId>org.wildfly.swarm</groupId>
    <artifactId>jaxrs</artifactId>
  </dependency>
  <dependency>
    <groupId>org.wildfly.swarm</groupId>
    <artifactId>remoting</artifactId>
  </dependency>
</dependencies>

测试MDB很简单:

@MessageDriven(activationConfig = {
    @ActivationConfigProperty(propertyName = "acknowledgeMode",
            propertyValue = "Auto-acknowledge"),
    @ActivationConfigProperty(propertyName = "destination",
            propertyValue = "request"),
    @ActivationConfigProperty(propertyName = "destinationType",
            propertyValue = "javax.jms.Queue")
})
public class TestMDB implements MessageListener {

    @Resource(name = "java:/ConnectionFactory")
    private QueueConnectionFactory queueConnectionFactory;


    @Override
    public void onMessage(Message message) {
        System.out.println(message);
    }
}

所以,我在寻找一个提示,为什么MDB无法访问资源适配器,即使该适配器已经部署,可见并且使用适当的名称也是如此。我希望现在这很简单,但我找不到它。

So, I'm looking for a hint why the MDB cannot access the resource adapter, even if it has been deployed, is visible and uses the appropriate name. I would expect, it is something simple at this point, but I cannot find it.

非常感谢!

PS:需要外部activemq服务器。使用JMS桥可能会起作用,但是会有一些无法接受的缺点(由于附加的跳,性能影响,jms-reply-to-dest不适用于jms桥)。

PS: The external activemq server is a requirement. Using a JMS bridge would probably work, but has some drawbacks which are not acceptable (performance impact due to additional 'hop', jms-reply-to destination don't work over jms bridge).

Arg,发布后我发现pom中至少存在一个问题:我使用了不匹配版本的swarm插件:swarm分数是2017.10.0,但插件是2017.4.0。纠正此问题会稍微改变错误症状:

Arg, after posting I found at least one problem in my pom: I used a mismatching version of the swarm plugin: The swarm fractions are 2017.10.0, but the plugin is 2017.4.0. Correcting this changes the error symptoms a bit:

2017-10-26 09:21:07,731 ERROR [stderr] (main) Caused by: java.lang.RuntimeException: org.wildfly.swarm.container.DeploymentException: org.wildfly.swarm.container.DeploymentException: WFSWARM0004: Deployment failed: {"WFLYCTL0412: Required services that are not installed:" => ["jboss.ra.activemq-rar"],"WFLYCTL0180: Services with missing/unavailable dependencies" => ["jboss.deployment.unit.\"mdbtest.jar\".component.TestMDB.CREATE is missing [jboss.ra.activemq-rar]"]}
2017-10-26 09:21:07,732 ERROR [stderr] (main)   at org.wildfly.swarm.spi.api.ClassLoading.withTCCL(ClassLoading.java:45)
2017-10-26 09:21:07,732 ERROR [stderr] (main)   at org.wildfly.swarm.container.runtime.ServerBootstrapImpl.bootstrap(ServerBootstrapImpl.java:114)
2017-10-26 09:21:07,732 ERROR [stderr] (main)   at org.wildfly.swarm.Swarm.start(Swarm.java:386)
2017-10-26 09:21:07,732 ERROR [stderr] (main)   at org.wildfly.swarm.Swarm.main(Swarm.java:720)
2017-10-26 09:21:07,732 ERROR [stderr] (main)   ... 6 more

所以下面似乎有一个类加载问题。将对此进行调查,但仍会为进一步的输入感到高兴

So there seems to be a classloading issue underneath. Will investigate this, but would still be glad for further input

上面的stacktrace似乎是无关紧要的:启用群集化应用程序的方式实际上有所不同:

The stacktrace above seems to be irrelevant: There is actually a difference how the swarmified application is started:


  • 以java -jar something.app开头:没有stacktrace

  • 以mv nwildfly-swarm:run开头:上面的堆栈跟踪。

但是,基本原因是相同的(未找到依赖项)。我认为Maven插件在调用中增加了一层,记录了额外的堆栈跟踪,但是问题仍然相同。

However, the basic cause is the same (dependencies not found). I interpret it that the maven plugin adds an additional layer to the invocation, that logs the additional stacktrace, but the issue is still the same.

推荐答案

最后,几个小时后,我自己解决了问题。不出所料,解决方案很简单,但并不明显...

Finally, after many hours I've solved the problem myself. As expected, the solution was simple but not obvious...

我从此处
经过一番认真的分析和调试,我发现资源适配器未正确部署:尽管在已安装的服务中提到了合适的部署单元(JMX控制台对找到它们很有帮助),资源适配器本身仍然不可用。
所有这些的解决方案是部署的名称:
为了正确地部署适配器,必须使用以下代码段:

One important hint I took from here. After some serious analysis and debugging sessions I've found, that the resource-adapter was not correctly deployed: while a suitable deployment unit was mentioned in the installed services (the JMX console is very helpful to find those), the resource adapter itself was still not available. The solution to all this was the name of the deployment: To deploy the adapter correctly, the following snippet has to be used:

swarm:
  deployment:
    org.apache.activemq:activemq-rar.rar:

请注意,必须省略maven 版本编号 ,而必须将mavenartifactId设置为使用(与上面的原始代码段比较)。由于swarm插件与Maven依赖管理紧密结合,因此可以弄清楚物理名称本身。在独立的Wildfly中,情况有所不同:它对Maven工件一无所知,因此必须使用物理档案名称。在standalone-full.xml中,它看起来像这样:

Note that the maven version number has to be omitted and just the maven artifactId has to be used (compare with my original snippet above). As the swarm plugin is tightly coupled to the maven dependency management, it figures out the physical name itself. In a standalone wildfly this is different: It doesn't know anything about maven artifacts, so the physical archive name has to be used. In the standalone-full.xml it would look like this:

<deployments>
   <deployment name="activemq-rar-5.15.0.rar" runtime-name="activemq-rar-5.15.0.rar">
       ...

更正存档名称后,部署便可以进行。由于存在ArtemisMQ适配器,JNDI中只剩下一个冲突(使用无法删除的YAML集群方法)。

When the name of the archive is corrected, the deployment works. Only thing left is a conflict in the JNDI due to the existence of the ArtemisMQ adapter (using the YAML approach of swarm it cannot be removed). So this has to be adapted as well.

为了完整起见,这是我最后工作的project-defaults.yaml:

So for completeness: Here is my finally working project-defaults.yaml:

swarm:
  deployment:
    org.apache.activemq:activemq-rar.rar:

  resource-adapters:
    resource-adapters:
      activemq-rar:
        # This is not the physical jar name, but the maven coordinates (without version!)
        archive: activemq-rar.rar
        transaction-support: LocalTransaction
        config-properties:
          ServerUrl:
            value: failover:tcp://localhost:61616
          UserName:
            value: admin
          Password:
            value: admin
          UseInboundSession:
            value: false

        connection-definitions:
            AMQConnectionFactory:
                jndi-name: ConnectionFactory
                class-name: org.apache.activemq.ra.ActiveMQManagedConnectionFactory
                enabled: true
                min-pool-size: 1
                max-pool-size: 20
                pool-prefill: false
                same-rm-override: false
                use-java-context: true

        admin-objects:
            REQUESTQUEUE:
                class-name: org.apache.activemq.command.ActiveMQQueue
                jndi-name: queues/request
                use-java-context: true
                config-properties:
                  PhysicalName: demo.request


  ejb3:
    default-resource-adapter-name: activemq-rar.rar
    default-mdb-instance-pool: mdb-strict-max-pool

  ee:
      default-bindings:
          jms-connection-factory: java:/ConnectionFactory


  management:
    security-realms:
      ManagementRealm:
        in-memory-authentication:
          users:
            admin:    
              password: admin                            
    http-interface-management-interface:
      allowed-origins: http://localhost:8080
      security-realm: ManagementRealm
      console-enabled: true

  messaging-activemq:
    servers:
      default:
        active: false
        connection-factories:
          InVmConnectionFactory:
            block-on-acknowledge: true
            entries:
            - "java:/ArtemisConnectionFactory"

  jca:
    archive-validation:
      enabled: false

  logging:
    loggers:
      org.jboss:
        level: INFO
      org.wildfly:
        level: INFO

这篇关于Wildfly-Swarm并通过资源适配器连接到外部activemq:WFLYCTL0412的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆