Search code examples
javajava-8spring-integrationspring-integration-dslspring-integration-ftp

Spring Integration DSL History issue


I have to setup the flows dynamically.

Example:

@Component
@Slf4j
public class FTPFlow {

    @Autowired
    private IntegrationFlowContext integrationFlowContext;

    @EventListener(ApplicationReadyEvent.class)
    public void setup(){


        integrationFlowContext.registration(flow()).register();

    }
    public IntegrationFlow flow() {

        DefaultFtpSessionFactory defaultFtpSessionFactory = new DefaultFtpSessionFactory();
        defaultFtpSessionFactory.setHost("localhost");
        defaultFtpSessionFactory.setPort(252);
        defaultFtpSessionFactory.setUsername("user");
        defaultFtpSessionFactory.setPassword("password");
        return IntegrationFlows.from(Ftp.inboundAdapter(defaultFtpSessionFactory).preserveTimestamp(true)
                        .localDirectory(new File("D:/tools/input"))
                        .regexFilter("yo.txt")
                        .remoteDirectory("/testing")
                        .deleteRemoteFiles(true),
                e -> e.poller(Pollers.fixedDelay(10, TimeUnit.SECONDS)))
                .transform((GenericTransformer<File, File>) file -> {

                    log.info("Dummy transformer. ");
                    return file;
                })
                .handle(o -> {

                    log.info("history {}", o.getHeaders());
                })
                .get();
    }
}

The springboot application:

@SpringBootApplication
@EnableMessageHistory
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

}

The headers don't contain the history but if I don't use the IntegrationContext and use the @Bean directly on the method flow then I can see the history.

Do I have to enable the history when using IntegrationFlowContext?


Solution

  • I actually found out myself. Just adding answer for other people

    When you are using IntegrationFlowContext you have to provide the "id" otherwise the history is not reserved.

     integrationFlowContext.registration(flow()).id("tesflow").register();