Spring integration Spring集成AggregatingMessageHandler.setGroupTimeoutExpression可见性

Spring integration Spring集成AggregatingMessageHandler.setGroupTimeoutExpression可见性,spring-integration,aggregator,Spring Integration,Aggregator,我的业务逻辑需要能够更改聚合器上配置的组超时 代码如下所示: @Autowired AggregatingMessageHandler messageAggregator; public void setTimeout(Integer timeoutValue) { Expression timeoutExpression = new SpelExpressionParser().parseExpression(timeoutValue.toString()); message

我的业务逻辑需要能够更改聚合器上配置的组超时

代码如下所示:

@Autowired
AggregatingMessageHandler messageAggregator;

public void setTimeout(Integer timeoutValue) {
    Expression timeoutExpression = new SpelExpressionParser().parseExpression(timeoutValue.toString());
    messageAggregator.setGroupTimeoutExpression(timeoutExpression);
}
问题是:

  • 我想向用户显示当前值,但是
  • 这个
可能的解决方案场景:

  • 我应该在这个bean上注入一个表达式,然后改变它的值吗,
    • 也就是说,它将在下次构建消息组时使用新结果重新计算表达式
  • 我应该用自己的具有公共setter的处理程序扩展AggregatingMessageHandler吗
  • 或者这是一个bug,应该在下一个版本中修复

不知道为什么称之为bug,但您的需求不是标准的

让我们一起想出一些解决办法

由于您将在运行时更改
组超时
,并且确实不需要
表达式
,因为您的值只是
整数
,所以可以使用
org.springframework.integration.expression.ValueExpression
作为
原子引用
bean的

在这种情况下,您只需向用户显示
当前值

@Autowired
private AtomicReference<ValueExpression> groupTimeoutExpression;

....
   this.groupTimeoutExpression.get().getValue();
@Autowired
私有原子引用groupTimeoutExpression;
....
this.groupTimeoutExpression.get().getValue();
并将该
AtomicReference
与新的
ValueExpression
一起用于当前值,并将最后一个值设置为
AggregatingMessageHandler

在应用程序启动时,您应该对初始
组超时执行相同的操作。或者只需将
复制/粘贴到
组超时
属性和
原子引用
bean


HTH

但我不想扩展AggregatingMessageHandler。顺便说一句,我通过context.xml将其实例化为,但我没有说要
extensingaggregatingmessagehandler
。我刚才指出在运行时使用
ValueExpression
,并利用
AtomicReference
提供一个钩子,向最终用户公开当前的
组超时值。您可以继续使用
setGroupTimeoutExpression
,无需扩展。对不起,我不清楚。