一个Java生产者使用spring连接池来管理100个MQ连接。默认情况下,每个MQ连接可以打开500个会话。
产生50000条消息后,将使用所有连接和会话。
我想知道:
我尝试了以下参数:idleTimeout + expiryTimeout + timeBetweenExpirationCheckMillis,但是:
我试图禁用kahadb持久性,但不起作用。
更新1:ActiveMQ连接池配置
<bean id="targetConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="failover:(tcp://activemq:61616)" />
</bean>
<bean id="connectionFactory" class="org.apache.activemq.pool.PooledConnectionFactory">
<property name="connectionFactory" ref="targetConnectionFactory" />
<property name="maxConnections" value="100" />
<property name="idleTimeout" value="30000" />
<property name="expiryTimeout" value="60000" />
<property name="maximumActiveSessionPerConnection" value="500" />
<property name="timeBetweenExpirationCheckMillis" value="30000" />
</bean>
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="connectionFactory"/>
<property name="receiveTimeout" value="10000"/>
</bean>
更新2:测试代码
package just.a.test;
import javax.jms.Destination;
import net.sf.json.JSONObject;
import org.springframework.jms.core.JmsTemplate;
@Component
public final class TestHandlerImpl{
@Autowired
private JmsTemplate jmsTemplate;
@Autowired
private Destination testQueue;
public void sendMessage(File binaryFile){
//read file, get one msg
JSONObject msg = processBinaryFile(binaryFile);
//send msg to queue
sendMessageToQueue(testQueue, msg.toString());
}
}
protected void sendMessageToQueue(Destination destination, final String msg) {
//this code will get one connection from pool
//create a new session
//and send the message
jmsTemplate.send(destination, new MessageCreator() {
public Message createMessage(Session session) throws JMSException {
return session.createTextMessage(msg);
}
});
}
}
Update3:
现在,我必须修改activemq-all.jar和common-pool.jar以使整个系统稳定。 我认为这是不对的。