I'm trying to combine Spring Batch and Spring Integration in one project. So my idea is that Spring Batch using StepBuilderFactory
reads the file with a custom method returning a String
while the .processor
creates a new Message<String>
using MessageBuilder
and sends that message into a channel...
So from here Spring Integration connects to that channel and starts working its workflow..
Any idea how to accomplish this? since i'm not getting any results besides getting the read String
to the .processor
but i can't reach Spring integration from there.
I read about the remotechunkingmanagerstepbuilderfactory
but it's not suited for my purposes because it sets automatically a specific type
@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();
}
To make Spring Integration works with annotation configuration or Java DSL, you need to be sure that you specify an @EnableIntegration
on some your @Configuration
class. Or consider to use Spring Boot.
See more info the docs: https://docs.spring.io/spring-integration/docs/5.2.3.RELEASE/reference/html/overview.html#configuration-enable-integration