Şu satırı dahil ederiz
getQueryableStore metoduimport org.springframework.cloud.stream.binder.kafka.streams.InteractiveQueryService;
KTable nesnesinin sorgulanmasını sağlar.
Örnek
Şöyle yaparız
@RestControllerimport org.apache.kafka.streams.state.ReadOnlyKeyValueStore;import org.springframework.cloud.stream.binder.kafka.streams.InteractiveQueryService;public class QueryController {@Autowiredprivate InteractiveQueryService queryService;@GetMapping(value = "/orders", produces = MediaType.APPLICATION_JSON_VALUE)public ResponseEntity<List<Item>> getItemsByCustomerIdAndPrice(
@RequestParam(value = "customerId") String customerId,@RequestParam(value = "price") Price price) {// get the item store for the given colourString storeName = ...;ReadOnlyKeyValueStore<String, OrderedItemsList> orderedItemsStore = queryServicea
.getQueryableStore(storeName,QueryableStoreTypes.keyValueStore());// get the items for the given customerOrderedItemsList orderedItems = orderedItemsStore.get(customerId);if (orderedItems != null) {List<Item> response = Mappers.getMapper(QueryMapper.class).getItems(orderedItems
.getItems());return ResponseEntity.ok(response);} else {return ResponseEntity.notFound().build();}}}
Hiç yorum yok:
Yorum Gönder