Spring integration Spring Integration 4.3中的异步ServiceActivator

Spring integration Spring Integration 4.3中的异步ServiceActivator,spring-integration,Spring Integration,SpringIntegration4.3引入了异步ServiceActivator,但我不知道在没有XML配置的情况下如何使用它们 相关问题提到将该功能添加到@ServiceActivator,但似乎没有实现 文件提到: 从版本4.3开始,现在可以将async属性设置为true(使用Java配置时设置为setAsync(true)) 但它没有提到调用该方法的对象。在我看来,您必须显式定义一个消息处理程序bean来调用该方法。 通常这是不必要的,用@ServiceActivator注释方法定义目标

SpringIntegration4.3引入了异步ServiceActivator,但我不知道在没有XML配置的情况下如何使用它们

相关问题提到将该功能添加到
@ServiceActivator
,但似乎没有实现

文件提到:

从版本4.3开始,现在可以将async属性设置为true(使用Java配置时设置为setAsync(true))

但它没有提到调用该方法的对象。在我看来,您必须显式定义一个消息处理程序bean来调用该方法。 通常这是不必要的,用
@ServiceActivator
注释方法定义目标bean就足够了


要么我遗漏了什么,要么基于注释的配置被排除在该功能之外。有人能解释一下吗?

你是对的;带注释的POJO方法当前不支持它

您可以使用configurerbean解决这个问题(自动连接消息处理程序并设置异步标志)

@springboot应用程序
公共类SO40962780应用程序{
公共静态void main(字符串[]args){
run(So40962780Application.class,args);
}
@InboundChannelAdapter(channel=“in”,poller=@poller(fixedRate=“5000”))
公共字符串gen(){
返回“foo”;
}
@ServiceActivator(inputChannel=“in”,outputChannel=“out”)
public ListenableFuture foo(字符串输入){
SettableListenableFuture=新的SettableListenableFuture();
future.set(在.toUpperCase()中);
回归未来;
}
@ServiceActivator(inputChannel=“out”)
公共无效系统(对象有效负载){
系统输出打印项次(有效载荷);
}
@豆子
公共异步配置器异步配置器(){
返回新的AsyncConfigurer();
}
公共静态类异步配置器{
@自动连线
@限定符(“so40962780Application.foo.serviceActivator.handler”)
私有AbstractReplyProducingMessageHandler-fooHandler;
@施工后
public void configureAsync(){
this.foodhandler.setAsync(true);
}
}
}

你是对的;带注释的POJO方法当前不支持它

您可以使用configurerbean解决这个问题(自动连接消息处理程序并设置异步标志)

@springboot应用程序
公共类SO40962780应用程序{
公共静态void main(字符串[]args){
run(So40962780Application.class,args);
}
@InboundChannelAdapter(channel=“in”,poller=@poller(fixedRate=“5000”))
公共字符串gen(){
返回“foo”;
}
@ServiceActivator(inputChannel=“in”,outputChannel=“out”)
public ListenableFuture foo(字符串输入){
SettableListenableFuture=新的SettableListenableFuture();
future.set(在.toUpperCase()中);
回归未来;
}
@ServiceActivator(inputChannel=“out”)
公共无效系统(对象有效负载){
系统输出打印项次(有效载荷);
}
@豆子
公共异步配置器异步配置器(){
返回新的AsyncConfigurer();
}
公共静态类异步配置器{
@自动连线
@限定符(“so40962780Application.foo.serviceActivator.handler”)
私有AbstractReplyProducingMessageHandler-fooHandler;
@施工后
public void configureAsync(){
this.foodhandler.setAsync(true);
}
}
}

谢谢,很好的解决方法,我自己不会想到。但我很好奇为什么注释中不支持它,因为它似乎是有意这样做的。疏忽?还是某种意想不到的困难?乍一看,这似乎很简单,只是一个疏忽。工厂bean支持它,但不支持注释。请随意打开一个JIRA问题。谢谢,很好的解决方法,我自己不会想到它。我很好奇为什么注释中不支持它,因为它似乎是有意这样做的。疏忽?还是某种意想不到的困难?乍一看,这似乎很简单,只是一个疏忽。工厂bean支持它,但不支持注释。请随意打开JIRA问题。
@SpringBootApplication
public class So40962780Application {

    public static void main(String[] args) {
        SpringApplication.run(So40962780Application.class, args);
    }

    @InboundChannelAdapter(channel = "in", poller = @Poller(fixedRate = "5000"))
    public String gen() {
        return "foo";
    }

    @ServiceActivator(inputChannel = "in", outputChannel = "out")
    public ListenableFuture<String> foo(String in) {
        SettableListenableFuture<String> future = new SettableListenableFuture<>();
        future.set(in.toUpperCase());
        return future;
    }

    @ServiceActivator(inputChannel = "out")
    public void syso(Object payload) {
        System.out.println(payload);
    }

    @Bean
    public AsyncConfigurer asyncConfigurer() {
        return new AsyncConfigurer();
    }

    public static class AsyncConfigurer {

        @Autowired
        @Qualifier("so40962780Application.foo.serviceActivator.handler")
        private AbstractReplyProducingMessageHandler fooHandler;

        @PostConstruct
        public void configureAsync() {
            this.fooHandler.setAsync(true);
        }

    }

}