[英]Spring Batch: chunk over enum and pass it to the reader
在我们的域中,我们列出了我们的服务在其中活跃的城市。 使用Spring批处理,我想调用带有城市名称参数的REST Web服务。
也许我很想使用库,但是我的意思是这样的:
@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);
}
如果我理解正确,则需要遍历一个城市列表,并为每个城市打电话给休息服务。 如果正确,请按以下步骤进行:
例如:
@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;
}
};
}
希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.