温馨提示:本文翻译自stackoverflow.com,查看原文请点击:java - Connecting Spring batch to Spring integration workflow
java spring spring-batch spring-integration spring-integration-dsl

java - 将Spring批处理连接到Spring集成工作流

发布于 2020-04-18 13:16:23



我正在尝试在一个项目中结合使用Spring Batch和Spring Integration。所以我的想法是,使用Spring Batch的StepBuilderFactory读取该文件与自定义方法返回一个String,而.processor创建一个新的Message<String>使用MessageBuilder和消息发送到一个通道......
从这里所以Spring集成连接到该通道并开始工作的工作流程..

任何想法如何做到这一点?因为除了读取内容之外我没有得到任何结果String.processor但是我无法从那里到达Spring集成。我阅读了有关的信息,remotechunkingmanagerstepbuilderfactory但它不适合我的用途,因为它会自动设置特定的类型

 @Bean
    public TaskletStep managerStep() throws Exception {

        return managerStepBuilderFactory.get("managerStep")
                .<String, String>chunk(5)
                .reader(readFile())
                .processor(new MessageProcess())//write String into Message and send it to Channel
                .writer(doSomething())//not important
                .build();
    }

public class MessageProcess implements ItemProcessor<String, String> {

    @Override
    public String process(String readString) throws Exception {
        Message<String> message = MessageBuilder.withPayload(item).build();
        channel().send(message); //sending message to channel
        return "item";

    }
}

    @Bean
    public IntegrationFlow workflow() {
        return IntegrationFlows
                .from(channel())
                .handle(checkMessage()) //checkMessage reads payload from Message<?> message
                .get();
    }

    @Bean
    public DirectChannel channel() {
        return new DirectChannel();
    }

查看更多

提问者
pepe
被浏览
93
Artem Bilan 2020-02-05 22:42

为了使Spring Integration与注释配置或Java DSL一起使用,您需要确保@EnableIntegration在您的@Configuration类中指定一个或者考虑使用Spring Boot。

有关更多信息,请参阅文档:https : //docs.spring.io/spring-integration/docs/5.2.3.RELEASE/reference/html/overview.html#configuration-enable-integration