Java 如何配置spring以正确关闭ActiveMQ会话或连接?
java生产者使用spring连接池来管理100个MQ连接。默认情况下,每个MQ连接可以打开500个会话 生成50000条消息后,将使用所有连接和会话Java 如何配置spring以正确关闭ActiveMQ会话或连接?,java,spring,activemq,Java,Spring,Activemq,java生产者使用spring连接池来管理100个MQ连接。默认情况下,每个MQ连接可以打开500个会话 生成50000条消息后,将使用所有连接和会话 从spring连接池中获取新连接(首先从池中获取连接,然后创建新会话)将非常缓慢 关闭连接需要很长时间 ActiveMQ服务器将使用大量内存 我想知道: 如何删除或重用连接创建的会话 何时关闭mq连接 我尝试了以下参数:idleTimeout+expiryTimeout+timebetweenExirationCheckMillis,但是
- 从spring连接池中获取新连接(首先从池中获取连接,然后创建新会话)将非常缓慢李>
- 关闭连接需要很长时间
- ActiveMQ服务器将使用大量内存
- 如何删除或重用连接创建的会话李>
- 何时关闭mq连接
- 当系统长时间非常繁忙时。整个系统将越来越慢。ActiveMQ将使用越来越多的内存
- 当系统非常忙时,突然空闲,然后突然非常忙。TimeBetweenNexPirationCheckMillis不够快,无法关闭所有连接。连接池将尝试关闭所有超时连接(idleTimeout或expiryTimeout),然后打开一个新连接。整个系统将卡住10-20分钟
<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>
更新3:
现在,我必须修改activemq-all.jar和common-pool.jar,以使整个系统保持稳定。
我认为这是不对的。为什么一个客户端使用50000个会话?一个还不够吗?当连接完成后,它不应该关闭连接,所以打开到队列的连接发送消息,关闭连接,池将保持它实际打开,并使其处于打开状态以供重用,让池实际关闭连接,想想生产者/消费者之间的紧密连接,即getfrompool()和releasetopool()@user207421每次应用程序从池中获得连接时,连接池将打开一个新会话。代码在common pool.jar中。@TheresaForster当系统忙时,连接池没有机会关闭连接。将会有越来越多的会话,ActiveMQ服务器将使用越来越多的内存。它会说什么时候关闭连接-使用后立即应答。因为池保持真正的连接打开,但您希望尽快释放
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);
}
});
}
}