向ActiveMQ嵌入式代理发送消息挂起

时间:2015-01-28 22:02:03

标签: apache-camel activemq

我想在单元测试中模拟我的activemq实例。所以我将队列设置为:

    camelContext = new DefaultCamelContext();
    camelContext.setErrorHandlerBuilder(new LoggingErrorHandlerBuilder());
    camelContext.getShutdownStrategy().setTimeout(SHUTDOWN_TIMEOUT_SECONDS);

    routePolicy = new RoutePolicy();
    routePolicy.setCamelContext(camelContext);

    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
    connectionFactory.setBrokerURL("vm:localhost");
    // use a pooled connection factory between the module and the queue
    pooledConnectionFactory = new PooledConnectionFactory(connectionFactory);

    // how many connections should there be in the session pool?
    pooledConnectionFactory.setMaxConnections(this.maxConnections);
    pooledConnectionFactory.setMaximumActiveSessionPerConnection(this.maxActiveSessionPerConnection);
    pooledConnectionFactory.setCreateConnectionOnStartup(true);
    pooledConnectionFactory.setBlockIfSessionPoolIsFull(false);

    JmsConfiguration jmsConfiguration = new JmsConfiguration(pooledConnectionFactory);
    jmsConfiguration.setDeliveryPersistent(false);

    ActiveMQComponent activeMQComponent = ActiveMQComponent.activeMQComponent("vm:localhost");

但是,当我像这样向队列发送消息时:

producerTemplate.sendBody(uri, message);

该过程挂起

FailoverTransport.oneway:600

任何想法使用嵌入式代理我可能做错了什么?连接到tcp端点时,这一切都正常。

1 个答案:

答案 0 :(得分:0)

您需要将URL更改为vm://localhost(甚至vm://localhost?broker.persistent=false,这在单元测试中很常见,以避免磁盘上的临时数据。)

相关问题