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

问题描述 投票:0回答:1

我正在尝试在一个项目中结合使用Spring Batch和Spring Integration。所以我的想法是,使用StepBuilderFactory的Spring Batch通过返回String的自定义方法读取文件,而.processor使用Message<String>创建新的MessageBuilder并将该消息发送到通道中。因此,Spring Integration从此处连接到该渠道并开始工作其工作流程。任何想法如何做到这一点?因为除了将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();
    }
java spring spring-integration spring-batch spring-integration-dsl
1个回答
0
投票

要使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

© www.soinside.com 2019 - 2024. All rights reserved.