初始化PooledConnectionFactory时,CamelContext正在关闭

时间:2017-11-09 12:24:07

标签: java apache-camel activemq connection-pooling wildfly-10

我尝试使用ActiveMQComponent通过camel cdi初始化org.apache.activemq.pool.PooledConnectionFactor。 使用ActiveMQConnectionFactory,这可以正常工作。

我还添加了一些日志,并注意到当PooledConnectionFactoryCamelContext关闭时。在构建和部署时 我用JMSConfigurations等尝试了许多不同的方法,但仍然没有运气。

这可能是什么原因?

错误日志。

17:45:07,043 INFO  [org.apache.camel.impl.DefaultCamelContext] (MSC service thread 1-6) Apache Camel 2.19.3 (CamelContext: camel_cdi_context) is starting
17:45:07,044 INFO  [org.apache.camel.management.ManagedManagementStrategy] (MSC service thread 1-6) JMX is enabled
17:45:07,064 INFO  [org.wildfly.extension.camel] (MSC service thread 1-6) Camel context starting: camel_cdi_context
17:45:07,064 INFO  [org.wildfly.extension.camel] (MSC service thread 1-2) Bound camel naming object: java:jboss/camel/context/camel_cdi_context
17:45:07,095 INFO  [org.apache.camel.impl.DefaultRuntimeEndpointRegistry] (MSC service thread 1-6) Runtime endpoint registry is in extended mode gathering usage statistics of all incoming and outgoing endpoints (cache limit: 1000)
17:45:07,131 INFO  [stdout] (MSC service thread 1-6) Creating ActiveMQ Component
17:45:07,131 INFO  [stdout] (MSC service thread 1-6) createActiveMQComponent().connectionFactory : org.apache.activemq.ActiveMQConnectionFactory@6e871efa
17:45:07,131 INFO  [stdout] (MSC service thread 1-6) createActiveMQComponent(). : mark-1
17:45:07,135 INFO  [org.apache.camel.impl.DefaultCamelContext] (MSC service thread 1-6) Apache Camel 2.19.3 (CamelContext: camel_cdi_context) is shutting down
17:45:07,137 INFO  [org.wildfly.extension.camel] (MSC service thread 1-6) Camel context stopped: camel_cdi_context

我可以继续使用ActiveMQConnectionFactory并以不同方式处理maximumConnections / timeouts。 但我喜欢最好的。

ActiveMQComponentProducer.java

@ApplicationScoped
public class ActiveMQComponentProducer {

    @Produces
    @Named("activemqx")
    public ActiveMQComponent createActiveMQComponent() {

        System.out.println("Creating ActiveMQ Component");

        ActiveMQComponent activeMQComponent = ActiveMQComponent.activeMQComponent();
        String connectionString = "tcp://localhost:61616";

        ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(connectionString);
        System.out.println("createActiveMQComponent().connectionFactory : " + connectionFactory);

        PooledConnectionFactory pooledConnectionFactory = null;
        System.out.println("createActiveMQComponent(). : mark-1");

        try {
            pooledConnectionFactory = new PooledConnectionFactory(connectionFactory);
        } catch (Exception e) {
            System.out.println("createActiveMQComponent(). : "+e);
        }
        System.out.println("createActiveMQComponent(). : mark-2");

        activeMQComponent.setConnectionFactory(pooledConnectionFactory);
        return activeMQComponent;
    }

}
  • 骆驼版:2.19
  • Wildfly版本:10.1.0
  • Camel Patch版本:wildfly-camel-patch-4.9.0

1 个答案:

答案 0 :(得分:1)

您可能遇到了类加载问题。

在WildFly-Camel 4.9.0版本中,PooledConnectionFactory不会自动导出到部署类路径上。此问题在将来的版本中已得到修复,并且已被此问题跟踪:

https://github.com/wildfly-extras/wildfly-camel/issues/2199

作为一种变通方法,您可以通过org.apache.activemq描述符为部署添加jboss-deployment-structure.xml的模块依赖关系。将其放在META-INF内进行JAR部署,或WEB-INF进行WAR部署。

<jboss-deployment-structure>
    <deployment>
        <dependencies>
            <module name="org.apache.activemq" />
        </dependencies>
    </deployment>
</jboss-deployment-structure>