@ReleaseStrategy – Spring Integration – 自定义实现

huangapple go评论121阅读模式
英文:

@ReleaseStrategy - Spring Integration - Custom implementation

问题

请告诉我是否有一种方法可以使用@ReleaseStrategy定义MessageGroup并将其与@Aggregator相关联。

我有以下方式定义的POJO,但不确定如何将@Aggregator与其关联:

public class FooReleaseStrategy {

    @ReleaseStrategy
    public boolean canRelease(MessageGroup group) {
        return group.isComplete();
    }

}

我有@Aggregator@CorrelationStratgy,作为配置的一部分进行了定义:

@Aggregator(inputChannel="sftpChannel", outputChannel="aggregateChannel")
public List<Message<?>> aggregateFiles(List<Message<?>> messages) {
    return messages;
}

基于文件名的@CorrelationStrategy

如果有人能够提供关于@ReleaseStrategy的关联示例,将会非常有帮助。

根据评论,我打算创建一个聚合器工厂Bean,以查看它是否适用于我的用例:

@Bean
@ServiceActivator(inputChannel = "sftpChannel")
public FactoryBean<MessageHandler> aggregatorFactoryBean() {
    AggregatorFactoryBean aggregatorBean = new AggregatorFactoryBean();
    aggregatorBean.setProcessorBean(new CustomAggregator());
    aggregatorBean.setMethodName("aggregate");
    aggregatorBean.setMessageStore(new SimpleMessageStore());
    aggregatorBean.setReleaseStrategy(messageGroup -> {
        return messageGroup.isComplete();
    });
    aggregatorBean.setOutputChannel(aggregatorFileChannel());
    aggregatorBean.setExpireGroupsUponTimeout(true);
    aggregatorBean.setGroupTimeoutExpression(new ValueExpression<>(1000L));
    aggregatorBean.setSendPartialResultOnExpiry(false);
    aggregatorBean.setExpireGroupsUponCompletion(true);
    return aggregatorBean;
}
英文:

Please let me know if there is way to define @ReleaseStrategy with MessageGroup and associate it with @Aggregator.

I have POJO defined as below but not sure how would I associate a @Aggregator to it

public class FooReleaseStrategy {

      @ReleaseStrategy
      public boolean canRelease(MessageGroup group) {
         return group.isComplete();
      }

}

I have @Aggregator and @CorrelationStratgy defined part of configuration.

      @Aggregator(inputChannel=&quot;sftpChannel&quot; outputChannel=&quot;aggregateChannel&quot;)
         public List&lt;Message&lt;?&gt;&gt; aggregateFiles(List&lt;Message&lt;?&gt;&gt; messages) {
         return messages;
      }

@CorrelationStrategy based on filename.

Would be very helpful if someone can shed some light on @ReleaseStrategy association with example if possible.

Based on the comments, I am planning on the create a aggregator factory bean to see if works for my use-case

    @Bean
    @ServiceActivator(inputChannel = &quot;sftpChannel&quot;)
    public FactoryBean&lt;MessageHandler&gt; aggregatorFactoryBean( ) {
        AggregatorFactoryBean aggregatorBean = new AggregatorFactoryBean();
        aggregatorBean.setProcessorBean(new CustomAggregator());
        aggregatorBean.setMethodName(&quot;aggregate&quot;);
        aggregatorBean.setMessageStore(new SimpleMessageStore());
        aggregatorBean.setReleaseStrategy(messageGroup -&gt; {
            return messageGroup.isComplete();
        });
        aggregatorBean.setOutputChannel(aggregatorFileChannel());
        aggregatorBean.setExpireGroupsUponTimeout(true);
        aggregatorBean.setGroupTimeoutExpression(new ValueExpression&lt;&gt;(1000L));
        aggregatorBean.setSendPartialResultOnExpiry(false);
        aggregatorBean.setExpireGroupsUponCompletion(true);
        return aggregatorBean;
    }

答案1

得分: 1

如果您想使用 @Aggregator@ReleaseStrategy@CorrelationStrategy,请考虑将 AggregatorFactoryBean 配置为 @Bean,并在其上应用 @ServiceActivator 注解,用于指定那些 inputChanneloutputChannel

有关更多信息,请参阅文档:https://docs.spring.io/spring-integration/docs/5.4.0-M2/reference/html/message-routing.html#aggregator-annotations

英文:

If you want to use an @Aggregator, @ReleaseStrategy and @CorrelationStrategy, consider to configure an AggregatorFactoryBean as a @Bean and apply a @SerivceActivator annotation on it for those inputChannel and outputChannel.

See docs for more info: https://docs.spring.io/spring-integration/docs/5.4.0-M2/reference/html/message-routing.html#aggregator-annotations

答案2

得分: 0

当使用那种配置风格时,@Aggregator@CorrelationStrategy@ReleasStrategy 通常位于同一个 bean 中。

但是,您可以定义一个 ReleaseStrategyFactoryBean bean,它将根据您的 POJO 方法提供 ReleaseStrategy 的实现。

setTarget(myRSBean);

它会找到该注解。

英文:

When using that style of configuration, @Aggregator, @CorrelationStrategy and @ReleasStrategy are usually in the same bean.

You can, however, define a ReleaseStrategyFactoryBean bean that will provide an implementation of ReleaseStrategy based on your POJO method.

setTarget(myRSBean);

It will find the annotation.

huangapple
  • 本文由 发表于 2020年8月15日 03:37:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/63419094.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定