【发布时间】: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