1

我必须动态设置流程。

例子:

@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();
    }
}

springboot 应用程序:

@SpringBootApplication
@EnableMessageHistory
public class DemoApplication {

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

}

标头不包含历史记录,但如果我不使用 IntegrationContext 并@Bean直接在方法流上使用,那么我可以看到历史记录。

使用时是否必须启用历史记录IntegrationFlowContext

4

1 回答 1

2

我自己真的发现了。只是为其他人添加答案

使用IntegrationFlowContext 时必须提供,"id"否则不保留历史记录。

 integrationFlowContext.registration(flow()).id("tesflow").register();
于 2020-01-03T17:11:59.767 回答