我的Spring集成流程出现了一些问题

问题描述 投票:0回答:1

我使用Spring Boot 2.3.0版本和Spring Integration 5.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() ;                  
    }
spring-integration spring-integration-dsl spring-retry
1个回答
1
投票
.handle(returns MessageHandler)

如果它是一个普通的 MessageHandler,那么之后确实什么都不会发生。它什么也不返回(void),所以之后没有回复继续流转。handle(GenericHandler) 而不是。

© www.soinside.com 2019 - 2024. All rights reserved.