javax.jms.JMSException:在配置的阻止超时内没有可用的 ManagedConnections

javax.jms.JMSException: No ManagedConnections available within configured blocking timeout

当我在 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);
}

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

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

谢谢, 塞巴斯蒂安

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

但我认为真正的问题是我没有关闭连接。

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

最后好像有个“...”。代码块末尾实际缺少的是: connection.close();

这解决了我的连接问题。