我正在尝试在一个项目中结合使用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();
}
为了使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