当我在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);
}
如果我在消息之间留下一点空隙,我可以发送消息。但是,如果我在服务器上遇到更多困难,我会遇到上述异常。
我在哪里可以配置连接池大小等等? 使用后关闭连接时是否存在问题?
谢谢, 塞巴斯蒂安
答案 0 :(得分:2)
我想我找到了它:http://tomee.apache.org/jmsconnectionfactory-config.html
但我认为实际问题是我没有关闭连接。
在以下示例中:http://tomee.apache.org/tomcat-activemq.html
最后有一个“......”。代码块末尾实际缺少的是: connection.close()时;
这解决了我的连接问题。