【问题标题】:some problem with my Spring Integration flow我的 Spring 集成流程有一些问题
【发布时间】:2020-05-20 16:06:59
【问题描述】:

我正在使用带有 Spring Integration 5.3.0 的 spring boot 2.3.0 版本,不知何故我无法让下面的代码工作。应用程序启动,没有错误,但是当控制权来到 nextChannelFlow() 方法时,没有任何事情发生或打印。有人可以告诉我我错过了什么。任何帮助表示赞赏。谢谢。

@Configuration
@EnableIntegration
@EnableRetry
    Class MyIntegrationFlow
    .
    .

    @Bean
    public IntegrationFlow upstreamFlow(){
    return IntegrationFlows.from(someChannel())
    .handle(srcDirectory(), "receive")                               
    .filter(onlyCsvfiles())                    
    .handle(targetDirectory())// returns a FileWritingMessageHandler
    .channel(nextChannel())     //this is downstream                            
    .get();
    }

@Bean
    public MessageHandler targetDirectory() throws IOException {
        FileWritingMessageHandler handler = new FileWritingMessageHandler(targetFolder.getFile());
        handler.setExpectReply(false);
        return handler;
    }   

    @Bean
    public DirectChannel nextChannel(){
    return new DirectChannel();
    }

    @Bean
    public IntegrationFlow nextChannelFlow() {
//the below is that last line that gets printed in console. After this line, nothing gets printed and I see no errors too.
        System.out.println("inside nextChannel method ");

        return IntegrationFlows.from (nextChannel()) 
                .handle((GenericHandler<String>) (payload, headers) -> {
                    System.out.println("inside handle 1");
                    callSomeMethod();
                    System.out.println("inside handle 2");
                    return payload;                 
                })
                .log(Level.INFO, new LiteralExpression("came out of handle.")) //was trying to see if I can see any logs/errors at this line , but nothing displayed.
                .channel(checkXFBFlowChannel())//control doesn't go to this channel as well.
                .get();
    }   

    @Retryable(value={IllegalStateException.class}, maxAttempts=5,backoff=@Backoff(delay=3000))
    public void callSomeMethod() {
        System.out.println("simulate sample retry method");        
        throw new IllegalStateException() ;                  
    }

【问题讨论】:

  • &gt;System.out.println("inside nextChannel method "); 这与运行时无关;它只会在应用程序初始化(构建流程)期间打印。您需要显示上游流的真实代码而不是伪代码;我们无法猜测它在做什么。打开 DEBUG 日志记录通常足以调试运行时。
  • 查看我的答案以了解可能的原因。

标签: spring-integration spring-integration-dsl spring-retry


【解决方案1】:
.handle(returns MessageHandler)

如果它是一个普通的MessageHandler,那么在它之后确实不会发生任何事情。它不返回任何内容(无效),因此之后没有回复继续进行流程。 考虑改用handle(GenericHandler)

【讨论】:

  • 嗨 Artem,上游返回一个非空的 MessageHandler。我已经用适当的数据编辑了问题。
  • 但是你说handler.setExpectReply(false);。请参阅它的 JavaDocs。当它返回null 时,下游没有东西流了。
  • 感谢 Artem,在我删除此行 handler.setExpectReply(false); 后,控制权传递到下游。
猜你喜欢
  • 1970-01-01
  • 2016-03-02
  • 1970-01-01
  • 1970-01-01
  • 2021-07-09
  • 1970-01-01
  • 2018-05-31
  • 1970-01-01
  • 2015-01-16
相关资源
最近更新 更多