@ReleaseStrategy – Spring Integration – 自定义实现

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

@ReleaseStrategy - Spring Integration - Custom implementation

问题

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

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

  1. public class FooReleaseStrategy {
  2. @ReleaseStrategy
  3. public boolean canRelease(MessageGroup group) {
  4. return group.isComplete();
  5. }
  6. }

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

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

基于文件名的@CorrelationStrategy

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

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

  1. @Bean
  2. @ServiceActivator(inputChannel = "sftpChannel")
  3. public FactoryBean<MessageHandler> aggregatorFactoryBean() {
  4. AggregatorFactoryBean aggregatorBean = new AggregatorFactoryBean();
  5. aggregatorBean.setProcessorBean(new CustomAggregator());
  6. aggregatorBean.setMethodName("aggregate");
  7. aggregatorBean.setMessageStore(new SimpleMessageStore());
  8. aggregatorBean.setReleaseStrategy(messageGroup -> {
  9. return messageGroup.isComplete();
  10. });
  11. aggregatorBean.setOutputChannel(aggregatorFileChannel());
  12. aggregatorBean.setExpireGroupsUponTimeout(true);
  13. aggregatorBean.setGroupTimeoutExpression(new ValueExpression<>(1000L));
  14. aggregatorBean.setSendPartialResultOnExpiry(false);
  15. aggregatorBean.setExpireGroupsUponCompletion(true);
  16. return aggregatorBean;
  17. }
英文:

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

  1. public class FooReleaseStrategy {
  2. @ReleaseStrategy
  3. public boolean canRelease(MessageGroup group) {
  4. return group.isComplete();
  5. }
  6. }

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

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

@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

  1. @Bean
  2. @ServiceActivator(inputChannel = &quot;sftpChannel&quot;)
  3. public FactoryBean&lt;MessageHandler&gt; aggregatorFactoryBean( ) {
  4. AggregatorFactoryBean aggregatorBean = new AggregatorFactoryBean();
  5. aggregatorBean.setProcessorBean(new CustomAggregator());
  6. aggregatorBean.setMethodName(&quot;aggregate&quot;);
  7. aggregatorBean.setMessageStore(new SimpleMessageStore());
  8. aggregatorBean.setReleaseStrategy(messageGroup -&gt; {
  9. return messageGroup.isComplete();
  10. });
  11. aggregatorBean.setOutputChannel(aggregatorFileChannel());
  12. aggregatorBean.setExpireGroupsUponTimeout(true);
  13. aggregatorBean.setGroupTimeoutExpression(new ValueExpression&lt;&gt;(1000L));
  14. aggregatorBean.setSendPartialResultOnExpiry(false);
  15. aggregatorBean.setExpireGroupsUponCompletion(true);
  16. return aggregatorBean;
  17. }

答案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 的实现。

  1. 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.

  1. 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:

确定