[英]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.