Wildfly-Swarm并通过资源适配器连接到外部activemq:WFLYCTL0412

时间:2017-10-26 07:19:46

标签: deployment dependencies activemq wildfly swarm

所以我已经花了相当多的时间在这上面,但现在已经到了我完全在我的智慧结束的地步......

要求: 我试图将基于Wildfly 10.1.0的消息驱动bean连接到外部activemq 5.15.0服务器(' old' activemq,而不是artemis mq!)。 为此,我部署了资源适配器并调整了配置。 在野生蝇的标准部署中,这可行。我使用以下脚本设置容器:

# 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相关的类),并且它可以按预期工作。

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

"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]"]

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

要设置swarm容器,我使用以下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的相关部分如下:

<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无法访问资源适配器,即使它已经部署,也是可见的,并使用适当的名称。我希望,在这一点上它很简单,但我找不到它。

非常感谢!

PS:外部activemq服务器是必需的。使用JMS桥可能会起作用,但有一些不可接受的缺点(由于额外的&#39; hop&#39;,jms-reply-to destination不能在jms网桥上工作而对性能产生影响)。

编辑1

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

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

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

编辑2

上面的堆栈跟踪似乎无关紧要:swarmified应用程序的启动实际上有所不同:

  • 从java -jar something.app:No stacktrace
  • 开始
  • 从mv开始nwildfly-swarm:运行:上面的堆栈跟踪。

但是,基本原因是相同的(未找到依赖项)。我解释说maven插件为调用添加了一个额外的层,记录了额外的堆栈跟踪,但问题仍然是相同的。

1 个答案:

答案 0 :(得分:4)

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

我从here获得的一个重要提示。 经过一些严肃的分析和调试会议后,我发现资源适配器没有正确部署:虽然在已安装的服务中提到了一个合适的部署单元(JMX控制台非常有助于找到它们),但资源适配器本身是仍然没有。 所有这些的解决方案是部署的名称: 要正确部署适配器,必须使用以下代码段:

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

请注意,maven 版本号码 必须省略 ,只需使用maven artifactId(与上面的原始片段进行比较) )。由于swarm插件与maven依赖关系管理紧密耦合,因此它会找出物理名称本身。在独立的wildfly中,这是不同的:它对maven工件一无所知,因此必须使用物理存档名称。在standalone-full.xml中,它看起来像这样:

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

更正存档名称后,部署才有效。由于ArtemisMQ适配器的存在,只留下了JNDI中的冲突(使用群的YAML方法无法删除)。所以这也必须进行调整。

所以为了完整性:这是我最终工作的项目-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