spring-integrationspring-integration-dslspring-integration-sftp

spring integration error: one-way 'MessageHandler' and it isn't appropriate


I am writing a simple Integration flow to sftp a file to a remote server and want to stop the temporary file renaming on the remote server.

In order to achieve this, I tried creating the following flows in FilesTransferConfig configuration class:

  @Bean
  public MessageHandler requestHandler(
      FileTransferService service) {
    MessageHandler messageHandler = message -> {
      MessageHeaders headers = message.getHeaders();
      FileSubmitRequest payload = (FileSubmitRequest) message.getPayload();
      service.send(payload);
    };
    return messageHandler;
  }
@Bean(name = "requestChannel")
  public MessageChannel requestChannel() {return new DirectChannel();}
  
@Bean
      public IntegrationFlow mainFlow() throws IOException {
        return IntegrationFlow.from(requestChannel())
                .handle(requestHandler(null))
                .to(sftpTransferFlow());
      }

@Bean
  public IntegrationFlow sftpTransferFlow() throws IOException {
    return f -> {
      try {
        f.handle(Sftp.outboundAdapter(sftpSessionFactory(null))
                .useTemporaryFileName(false));
      } catch (IOException e) {
        throw new RuntimeException(e);
      }
    };

}

When I run the app, I am getting the following exception:

    Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.integration.dsl.IntegrationFlow]: Factory method 'mainFlow' threw exception with message: The 'currentComponent' (com.thebigscale.config.FilesTransferConfig$$Lambda$1431/0x00000008015e55b0@26bd2d7d) is a one-way 'MessageHandler' and it isn't appropriate to configure 'outputChannel'. This is the end of the integration flow.
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:177) ~[spring-beans-6.1.5.jar:6.1.5]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:644) ~[spring-beans-6.1.5.jar:6.1.5]
    ... 19 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: The 'currentComponent' (com.thebigscale.config.FilesTransferConfig $$Lambda$1431/0x00000008015e55b0@26bd2d7d) is a one-way 'MessageHandler' and it isn't appropriate to configure 'outputChannel'. This is the end of the integration flow.
    at org.springframework.integration.dsl.BaseIntegrationFlowDefinition.registerOutputChannelIfCan(BaseIntegrationFlowDefinition.java:2963) ~[spring-integration-core-6.2.3.jar:6.2.3]

I would like to know how where am I going wrong? Any pointers would be highly appreciated.


Solution

  • We don't know what is your .handle(requestHandler(null)), but apparently that is just a plain MessageHandler, but not the one which would produce a reply to the channel for that .to(sftpTransferFlow()).

    How does not look like that com.thebigscale.config.FilesTransferConfig$$Lambda$1431/0x00000008015e55b0@26bd2d7d is related to the .handle(requestHandler(null)) call.