java - CamelContext 在初始化 PooledConnectionFactory 时关闭

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

我正在尝试通过camel cdi使用org.apache.activemq.pool.PooledConnectionFactor初始化ActiveMQComponent。 使用ActiveMQConnectionFactory,效果很好。

我还添加了一些日志,并注意到当 PooledConnectionFactory 时,CamelContext 正在关闭。当它正在构建和部署时 我使用 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 并以不同的方式处理最大连接/超时。 但我喜欢拥有最好的。

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

}
  • Camel 版本:2.19
  • 野蝇版本:10.1.0
  • Camel 补丁版本:wildfly-camel-patch-4.9.0

最佳答案

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

在 WildFly-Camel 4.9.0 版本中,PooledConnectionFactory 不会自动导出到部署类路径中。此问题已在未来版本中修复,并通过此问题进行跟踪:

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

作为解决方法,您可以通过 jboss-deployment-struction.xml 描述符将 org.apache.activemq 的模块依赖项添加到您的部署中。将其放入 META-INF(对于 JAR 部署)或 WEB-INF(对于 WAR 部署)。

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

关于java - CamelContext 在初始化 PooledConnectionFactory 时关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47201787/

相关文章:

java - 清除或设置 null 到 java 中的对象

java - 绑定(bind) aws sqs 区域 Camel

java - Apache ActiveMQ 在多个消费者上的异常行为

java - 使用 WebDriver DesiredCapativity 将功能 'applicationCacheEnabled' 设置为 'false'

java:关于重写方法的继承问题

java - Apache Camel : How to persist property or header between multiple Exchanges after split and subsequent Exception?

java - ActiveMQ 不从队列中取出消息

java - ActiveMQ 中存在大量 SSL 客户端

java - 使用 Java 中的 Files API 复制目录及其中的所有内容

apache-camel - Apache Camel : access both request and reply message at end of route