为何TimeoutCountSequenceSizeReleaseStrategy设15分钟超时仍1分钟释放消息?
问题排查与修复
1. 释放策略配置用错属性(核心原因)
你在聚合器里写了release-strategy-expression="timeoutReleaseStrategy",但这个属性是用来编写SpEL表达式的,直接引用Bean得用release-strategy。这个错误导致Spring根本没加载你自定义的策略,直接使用了默认的TimeoutCountSequenceSizeReleaseStrategy(默认超时1分钟)。
把这行改成:
release-strategy="timeoutReleaseStrategy"
2. XML语法错误导致配置失效
你的聚合器标签还有两个语法问题,也会导致配置异常:
correlation-strategy-expression="headers['fileName']未闭合引号,补上引号:correlation-strategy-expression="headers['fileName']"- 重复定义了两个
id属性(id="customAggregator"和id="messageAggregator"),删除其中一个,保留唯一ID即可。
3. 构造参数顺序搞反了
Spring Integration 5.3版本中,TimeoutCountSequenceSizeReleaseStrategy的构造函数是先传超时时间,再传阈值。你当前配置先传阈值、再传超时,会导致实际超时时间被设为10000毫秒(10秒),需要调整参数顺序:
<bean id="timeoutReleaseStrategy" class="org.springframework.integration.aggregator.TimeoutCountSequenceSizeReleaseStrategy"> <constructor-arg name="timeout" value="900000"/> <!-- 15分钟 --> <constructor-arg name="threshold" value="10000"/> </bean>
(也可以用index属性明确指定参数顺序,比如index="0"对应超时、index="1"对应阈值,避免依赖参数名匹配的问题)
修复后的完整配置
<int:aggregator output-channel="messageOutFileChannel" send-partial-result-on-expiry="true" message-store="customMessageStore" correlation-strategy-expression="headers['fileName']" ref="messageAggregatorService" method="aggregateMessages" release-strategy="timeoutReleaseStrategy" expire-groups-upon-completion="true" expire-groups-upon-timeout="true" id="messageAggregator" input-channel="aggregatorInChannel" > </int:aggregator> <bean id="customMessageStore" class="org.springframework.integration.store.SimpleMessageStore"/> <bean id="timeoutReleaseStrategy" class="org.springframework.integration.aggregator.TimeoutCountSequenceSizeReleaseStrategy"> <constructor-arg name="timeout" value="900000"/> <!-- 15分钟 --> <constructor-arg name="threshold" value="10000"/> </bean>
内容的提问来源于stack exchange,提问作者coder
相关产品推荐
相关产品推荐

