【问题标题】:javax.jms.JMSException: No ManagedConnections available within configured blocking timeoutjavax.jms.JMSException:在配置的阻塞超时内没有可用的 ManagedConnections
【发布时间】:2015-08-10 21:37:04
【问题描述】:

当我在 Tomcat 中运行 ActiveMQ 时,在通过添加新消息访问服务器后收到以下异常:

javax.jms.JMSException: No ManagedConnections available within configured blocking timeout ( 5000 [ms] ) for pool org.apache.geronimo.connector.outbound.SinglePoolConnectionInterceptor@6581542c
at org.apache.activemq.ra.ActiveMQConnectionFactory.createConnection(ActiveMQConnectionFactory.java:101)
at org.apache.activemq.ra.ActiveMQConnectionFactory.createConnection(ActiveMQConnectionFactory.java:67)

我正在使用 Apache Tomee 来管理 ActiveMQ 队列。

我的ActiveMQ配置很简单:

<?xml version="1.0" encoding="UTF-8"?>
<tomee>
    <!-- see http://tomee.apache.org/containers-and-resources.html -->

    <!-- activate next line to be able to deploy applications in apps -->
    <!-- <Deployments dir="apps" /> -->

    <Resource id="MyJmsResourceAdapter" type="ActiveMQResourceAdapter">
        BrokerXmlConfig =  broker:(tcp://localhost:61616)
        ServerUrl       =  tcp://localhost:61616
    </Resource>

    <Resource id="MyJmsConnectionFactory" type="javax.jms.ConnectionFactory">
        ResourceAdapter = MyJmsResourceAdapter
    </Resource>

</tomee>

为了定义队列,我有一个简单的代码:

@Resource(name = "myQueue")
private Queue barQueue;

@Resource
private ConnectionFactory connectionFactory;

/**
 * Push Message to Queue
 *
 * @param payload
 * @throws JMSException
 */
private void pushToQueue(Serializable payload) throws JMSException {
    Connection connection = connectionFactory.createConnection();
    connection.start();

    // Create a Session
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

    // Create a MessageProducer from the Session to the Topic or Queu
    MessageProducer producer = session.createProducer(barQueue);
    producer.setDeliveryMode(DeliveryMode.PERSISTENT);

    // Create a message
    ObjectMessage message = session.createObjectMessage(payload);

    // Tell the producer to send the message
    producer.send(message);
}

如果我在消息之间留有一点空隙,我可以很好地发送消息。但是,如果我更用力地访问服务器,我会在上述异常中运行。

在哪里可以配置连接池大小等? 使用后关闭连接是否有问题?

谢谢, 塞巴斯蒂安

【问题讨论】:

    标签: java tomcat jms activemq apache-tomee


    【解决方案1】:

    我想我找到了:http://tomee.apache.org/jmsconnectionfactory-config.html

    但我认为实际的问题是我没有关闭连接。

    在示例中:http://tomee.apache.org/tomcat-activemq.html

    最后有一个“...”。代码块末尾实际上缺少的是: 连接.close();

    这解决了我的连接问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-02
      • 1970-01-01
      • 2016-09-17
      • 2015-03-28
      • 2013-12-07
      • 2015-04-21
      • 2013-11-16
      • 1970-01-01
      相关资源
      最近更新 更多