[英]Spring Batch: chunk over enum and pass it to the reader
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. 使用Spring批处理,我想调用带有城市名称参数的REST Web服务。
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. 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.