英文:
@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="sftpChannel" outputChannel="aggregateChannel")
public List<Message<?>> aggregateFiles(List<Message<?>> 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 = "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;
}
答案1
得分: 1
如果您想使用 @Aggregator、@ReleaseStrategy 和 @CorrelationStrategy,请考虑将 AggregatorFactoryBean 配置为 @Bean,并在其上应用 @ServiceActivator 注解,用于指定那些 inputChannel 和 outputChannel。
有关更多信息,请参阅文档: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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论