如何在spring集成流中配置触发器以从调用消息源的方法中获取值?

时间:2017-09-19 23:16:32

标签: spring-integration

如何在spring integration flow中配置触发器以从调用消息源的方法获取值并在另一个流中启动它?

@Bean
public IntegrationFlow integrationFlow() {

   return IntegrationFlows.from(messageSource,channelSpec -> channelSpec.poller(Pollers.trigger(new SomeTrigger())).handle(...).get() 

}
@Bean
public MessageSource<?> messageSource() {
   MethodInvokingMessageSource source = new MethodInvokingMessageSource();
   source.setObject(new Random());
   source.setMethod("nextInt");
}

@Bean
public IntegrationFlow someOtherFlow() {
   return IntegrationFlows.from("messageChannel")
                           ///some logic to trigger and get the value of random int
}

1 个答案:

答案 0 :(得分:0)

MessageSourcereceive()方法,所以你可以这样做:

@Bean
public MessageSource<?> randomIntSource() {
    MethodInvokingMessageSource source = new MethodInvokingMessageSource();
    source.setObject(new Random());
    source.setMethodName("nextInt");
    return source;
}

@Bean
public IntegrationFlow someOtherFlow() {
    return IntegrationFlows.from("messageChannel")
            .handle(randomIntSource(), "receive")
            .handle(System.out::println)
            .get();
}

注意.handle(randomIntSource(), "receive")