我正在尝试在一个项目中结合使用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();
}
要使Spring Integration与注释配置或Java DSL一起使用,您需要确保在某些@EnableIntegration
类上指定了@Configuration
。或考虑使用Spring Boot。