gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 08:48:29 24 4
gpt4 key购买 nike

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

这解决了我的连接问题。

关于javax.jms.JMSException : No ManagedConnections available within configured blocking timeout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31929611/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com