In our domain, we have list of cities which our service is active there. Using Spring batch I would like to call a REST web-service with parameter of city names.
Maybe I'm wring in the usage of library, but I mean some thing like this:
@Bean
public Step step1(ItemWriter writer) {
return stepBuilderFactory.get("step1")
.chunk(InstalledCities.values())
.reader(reader())
.processor(processor())
.writer(writer)
.build();
@Bean
public ItemReader<BikerCashOutDto> reader(InstalledCities city) {
theSrevice.call(city);
}
If I understand correctly, you need to iterate over a list of cities and for each city, call a rest service. If this is correct, here is how you can proceed:
For example:
@Bean
public ItemReader<City> reader(List<City> cities) {
return new ListItemReader<>(cities); // or get cities from InstalledCities
}
@Bean
public ItemProcessor<City, City> itemProcessor(TheSrevice theSrevice) {
return new ItemProcessor<City, City>() {
@Override
public City process(City city) throws Exception {
Result result = theSrevice.call(city);
// use service result if any or enrich city item
return city;
}
};
}
Hope this helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.