0

I'm using spring boot 2.3.0 version with Spring Integration 5.3.0 and somehow I'm not able to get the below code working.The app starts up, no errors but when control comes to the nextChannelFlow() method, nothing is happening or printed. Can someone please tell me what I'm missing. Any help is appreciated. Thanks.

@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() ;                  
    }
kkk
  • 166
  • 2
  • 18
  • `>System.out.println("inside nextChannel method ");` That has nothing to do with the runtime; it will only be printed during application initialization (building the flows). You need to show the real code for the upstream flow instead of pseudo code; we can't guess what it is doing. Turning on DEBUG logging is usually enough to debug the runtime. – Gary Russell May 20 '20 at 17:02
  • See my answer for possible cause. – Artem Bilan May 20 '20 at 17:22

1 Answers1

1
.handle(returns MessageHandler)

If it is a plain MessageHandler, then indeed nothing going to happen after it. It returns nothing (void), so no reply to go on through the flow after that. Consider to use a handle(GenericHandler) instead.

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • hi Artem, the upstream returns a non-void MessageHandler.i have edited the question with proper data. – kkk May 20 '20 at 18:26
  • But you said there `handler.setExpectReply(false);`. See its JavaDocs. When it returns `null`, there is nothing to flow downstream. – Artem Bilan May 20 '20 at 18:33
  • Thanks Artem, after I removed this line `handler.setExpectReply(false);` the control passes to downstream. – kkk May 21 '20 at 06:52