Spring CachingConnectionFactory 在空闲时不收割

Spring CachingConnectionFactory not reaping when idle

我在下面的配置中使用 spring CachingConnectionFactory 来缓存 MQ 会话。我可以看到缓存按预期工作:

我的应用程序在消息流量中存在短暂的峰值。因此,当出现峰值时,会话大小会膨胀并在峰值过后很长时间内保持不变。我正在寻找一种在特定的不活动时间后收获这些空闲会话的方法。无论如何要实现这一目标?

<jee:jndi-lookup id="mqQueueConnectionFactory" jndi-name="java:comp/env/jms/MyJMSQueueConnectionFactory" />

<bean id="userConnectionFactory" class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter">
    <property name="targetConnectionFactory" ref="mqQueueConnectionFactory"></property>
</bean>
<bean id="queueConnectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
    <property name="targetConnectionFactory" ref="userConnectionFactory"></property>
    <property name="reconnectOnException" value="${ssa.mq.cachesession}"></property>
    <property name="cacheProducers" value="${ssa.mq.cacheproducer}"></property>
    <property name="sessionCacheSize" value="${ssa.mq.producer.sessionsize}"></property>
    <property name="cacheConsumers" value="${ssa.mq.cacheconsumers}"></property>
</bean>

你可以减少sessionCacheSize;超过缓存大小时关闭的任何会话将在下次使用时物理关闭。