org.apache.kafka.streams.state.ReadOnlyKeyValueStore Java Examples
The following examples show how to use
org.apache.kafka.streams.state.ReadOnlyKeyValueStore.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KafkaStorageHttpService.java From zipkin-storage-kafka with Apache License 2.0 | 6 votes |
void addResults( QueryRequest request, ReadOnlyKeyValueStore<String, List<Span>> tracesStore, List<List<Span>> traces, List<String> traceIds, KeyValueIterator<Long, Set<String>> spanIds ) { spanIds.forEachRemaining(keyValue -> { for (String traceId : keyValue.value) { if (!traceIds.contains(traceId)) { List<Span> spans = tracesStore.get(traceId); if (spans != null && !spans.isEmpty() && request.test(spans)) { // apply filters traceIds.add(traceId); // adding to check if we have already add it later traces.add(spans); } } } }); }
Example #2
Source File: StreamsRegistryConfiguration.java From apicurio-registry with Apache License 2.0 | 6 votes |
@Produces @ApplicationScoped public ReadOnlyKeyValueStore<Long, Str.TupleValue> globalIdKeyValueStore( KafkaStreams streams, HostInfo storageLocalHost, StreamsProperties properties ) { return new DistributedReadOnlyKeyValueStore<>( streams, storageLocalHost, properties.getGlobalIdStoreName(), Serdes.Long(), ProtoSerde.parsedWith(Str.TupleValue.parser()), new DefaultGrpcChannelProvider(), true, (filter, over, id, tuple) -> true ); }
Example #3
Source File: MetricsResource.java From kafka-streams-example with Apache License 2.0 | 6 votes |
/** * Query local state store to extract metrics * * @return local Metrics */ private Metrics getLocalMetrics() { HostInfo thisInstance = GlobalAppState.getInstance().getHostPortInfo(); KafkaStreams ks = GlobalAppState.getInstance().getKafkaStreams(); String source = thisInstance.host() + ":" + thisInstance.port(); Metrics localMetrics = new Metrics(); ReadOnlyKeyValueStore<String, Double> averageStore = ks .store(storeName, QueryableStoreTypes.<String, Double>keyValueStore()); LOGGER.log(Level.INFO, "Entries in store {0}", averageStore.approximateNumEntries()); KeyValueIterator<String, Double> storeIterator = averageStore.all(); while (storeIterator.hasNext()) { KeyValue<String, Double> kv = storeIterator.next(); localMetrics.add(source, kv.key, String.valueOf(kv.value)); } LOGGER.log(Level.INFO, "Local store state {0}", localMetrics); return localMetrics; }
Example #4
Source File: MetricsResource.java From kafka-streams-example with Apache License 2.0 | 6 votes |
/** * get Metrics for a machine * @param machine * @return */ private Metrics getLocalMetrics(String machine) { LOGGER.log(Level.INFO, "Getting Metrics for machine {0}", machine); HostInfo thisInstance = GlobalAppState.getInstance().getHostPortInfo(); KafkaStreams ks = GlobalAppState.getInstance().getKafkaStreams(); String source = thisInstance.host() + ":" + thisInstance.port(); Metrics localMetrics = new Metrics(); ReadOnlyKeyValueStore<String, Double> averageStore = ks .store(storeName, QueryableStoreTypes.<String, Double>keyValueStore()); LOGGER.log(Level.INFO, "Entries in store {0}", averageStore.approximateNumEntries()); localMetrics.add(source, machine, String.valueOf(averageStore.get(machine))); LOGGER.log(Level.INFO, "Metrics for machine {0} - {1}", new Object[]{machine, localMetrics}); return localMetrics; }
Example #5
Source File: KafkaStorageHttpService.java From zipkin-storage-kafka with Apache License 2.0 | 6 votes |
@Get("/autocompleteTags/:key") @ProducesJson public JsonNode getAutocompleteValues(@Param("key") String key) { try { if (!storage.traceSearchEnabled) return MAPPER.createArrayNode(); ReadOnlyKeyValueStore<String, Set<String>> autocompleteTagsStore = storage.getTraceStorageStream().store(AUTOCOMPLETE_TAGS_STORE_NAME, QueryableStoreTypes.keyValueStore()); Set<String> values = autocompleteTagsStore.get(key); ArrayNode array = MAPPER.createArrayNode(); if (values != null) values.forEach(array::add); return array; } catch (InvalidStateStoreException e) { LOG.debug("State store is not ready", e); throw e; } }
Example #6
Source File: KafkaStorageHttpService.java From zipkin-storage-kafka with Apache License 2.0 | 6 votes |
@Get("/autocompleteTags") @ProducesJson public JsonNode getAutocompleteTags() { try { if (!storage.traceSearchEnabled) return MAPPER.createArrayNode(); ReadOnlyKeyValueStore<String, Set<String>> autocompleteTagsStore = storage.getTraceStorageStream().store(AUTOCOMPLETE_TAGS_STORE_NAME, QueryableStoreTypes.keyValueStore()); ArrayNode array = MAPPER.createArrayNode(); try (KeyValueIterator<String, Set<String>> all = autocompleteTagsStore.all()) { all.forEachRemaining(keyValue -> array.add(keyValue.key)); } return array; } catch (InvalidStateStoreException e) { LOG.debug("State store is not ready", e); throw e; } }
Example #7
Source File: KafkaStorageHttpService.java From zipkin-storage-kafka with Apache License 2.0 | 6 votes |
@Get("/traceMany") public AggregatedHttpResponse getTraces(@Param("traceIds") String traceIds) { try { if (!storage.traceByIdQueryEnabled) return AggregatedHttpResponse.of(HttpStatus.NOT_FOUND); ReadOnlyKeyValueStore<String, List<Span>> store = storage.getTraceStorageStream() .store(TRACES_STORE_NAME, QueryableStoreTypes.keyValueStore()); List<List<Span>> result = new ArrayList<>(); for (String traceId : traceIds.split(",", 1000)) { result.add(store.get(traceId)); } return AggregatedHttpResponse.of(HttpStatus.OK, MediaType.JSON, writeTraces(result)); } catch (InvalidStateStoreException e) { LOG.debug("State store is not ready", e); return AggregatedHttpResponse.of(HttpStatus.SERVICE_UNAVAILABLE); } }
Example #8
Source File: KafkaStorageHttpService.java From zipkin-storage-kafka with Apache License 2.0 | 6 votes |
@Get("/traces/:trace_id") public AggregatedHttpResponse getTrace(@Param("trace_id") String traceId) { try { if (!storage.traceByIdQueryEnabled) return AggregatedHttpResponse.of(HttpStatus.NOT_FOUND); ReadOnlyKeyValueStore<String, List<Span>> store = storage.getTraceStorageStream() .store(TRACES_STORE_NAME, QueryableStoreTypes.keyValueStore()); List<Span> spans = store.get(traceId); return AggregatedHttpResponse.of( HttpStatus.OK, MediaType.JSON, SpanBytesEncoder.JSON_V2.encodeList(spans)); } catch (InvalidStateStoreException e) { LOG.debug("State store is not ready", e); return AggregatedHttpResponse.of(HttpStatus.SERVICE_UNAVAILABLE); } }
Example #9
Source File: RangeKeyValueQueryVerticle.java From kiqr with Apache License 2.0 | 6 votes |
@Override public void start() throws Exception { execute(Config.RANGE_KEY_VALUE_QUERY_ADDRESS_PREFIX, (abstractQuery, keySerde, valueSerde) -> { RangeKeyValueQuery query = (RangeKeyValueQuery) abstractQuery; ReadOnlyKeyValueStore<Object, Object> kvStore = streams.store(query.getStoreName(), QueryableStoreTypes.keyValueStore()); MultiValuedKeyValueQueryResponse response; try (KeyValueIterator<Object, Object> result = kvStore.range(deserializeObject(keySerde, query.getFrom()), deserializeObject(keySerde, query.getTo()))) { if (result.hasNext()) { Map<String, String> results = new HashMap<>(); while (result.hasNext()) { KeyValue<Object, Object> kvEntry = result.next(); results.put(base64Encode(keySerde, kvEntry.key), base64Encode(valueSerde, kvEntry.value)); } return new MultiValuedKeyValueQueryResponse(results); } else { return new MultiValuedKeyValueQueryResponse(Collections.emptyMap()); } } } ); }
Example #10
Source File: KafkaStorageHttpService.java From zipkin-storage-kafka with Apache License 2.0 | 6 votes |
@Get("/serviceNames/:service_name/remoteServiceNames") @ProducesJson public JsonNode getRemoteServiceNames(@Param("service_name") String serviceName) { try { if (!storage.traceSearchEnabled) return MAPPER.createArrayNode(); ReadOnlyKeyValueStore<String, Set<String>> store = storage.getTraceStorageStream() .store(REMOTE_SERVICE_NAMES_STORE_NAME, QueryableStoreTypes.keyValueStore()); Set<String> names = store.get(serviceName); ArrayNode array = MAPPER.createArrayNode(); if (names != null) names.forEach(array::add); return (array); } catch (InvalidStateStoreException e) { LOG.debug("State store is not ready", e); throw e; } }
Example #11
Source File: KafkaStorageHttpService.java From zipkin-storage-kafka with Apache License 2.0 | 6 votes |
@Get("/serviceNames/:service_name/spanNames") @ProducesJson public JsonNode getSpanNames(@Param("service_name") String serviceName) { try { if (!storage.traceSearchEnabled) return MAPPER.createArrayNode(); ReadOnlyKeyValueStore<String, Set<String>> store = storage.getTraceStorageStream() .store(SPAN_NAMES_STORE_NAME, QueryableStoreTypes.keyValueStore()); Set<String> names = store.get(serviceName); ArrayNode array = MAPPER.createArrayNode(); if (names != null) names.forEach(array::add); return array; } catch (InvalidStateStoreException e) { LOG.debug("State store is not ready", e); throw e; } }
Example #12
Source File: KafkaStorageHttpService.java From zipkin-storage-kafka with Apache License 2.0 | 6 votes |
@Get("/serviceNames") @ProducesJson public JsonNode getServiceNames() { try { if (!storage.traceSearchEnabled) return MAPPER.createArrayNode(); ReadOnlyKeyValueStore<String, String> store = storage.getTraceStorageStream() .store(SERVICE_NAMES_STORE_NAME, QueryableStoreTypes.keyValueStore()); ArrayNode array = MAPPER.createArrayNode(); try (KeyValueIterator<String, String> all = store.all()) { all.forEachRemaining(keyValue -> array.add(keyValue.value)); } return array; } catch (InvalidStateStoreException e) { LOG.debug("State store is not ready", e); throw e; } }
Example #13
Source File: AllKeyValuesQueryVerticle.java From kiqr with Apache License 2.0 | 6 votes |
@Override public void start() throws Exception { execute(Config.ALL_KEY_VALUE_QUERY_ADDRESS_PREFIX, (query, keySerde, valueSerde) -> { ReadOnlyKeyValueStore<Object, Object> kvStore = streams.store(query.getStoreName(), QueryableStoreTypes.keyValueStore()); MultiValuedKeyValueQueryResponse response; try (KeyValueIterator<Object, Object> result = kvStore.all()) { if (result.hasNext()) { Map<String, String> results = new HashMap<>(); while (result.hasNext()) { KeyValue<Object, Object> kvEntry = result.next(); results.put(base64Encode(keySerde, kvEntry.key), base64Encode(valueSerde, kvEntry.value)); } return new MultiValuedKeyValueQueryResponse(results); } else { return new MultiValuedKeyValueQueryResponse(Collections.emptyMap()); } } }); }
Example #14
Source File: ScalarKeyValueQueryVerticle.java From kiqr with Apache License 2.0 | 6 votes |
@Override public void start() throws Exception { execute(Config.KEY_VALUE_QUERY_ADDRESS_PREFIX, (abstractQuery, keySerde, valueSerde) -> { KeyBasedQuery query = (KeyBasedQuery) abstractQuery; Object deserializedKey = deserializeObject(keySerde, query.getKey()); ReadOnlyKeyValueStore<Object, Object> kvStore = streams.store(query.getStoreName(), QueryableStoreTypes.keyValueStore()); Object result = kvStore.get(deserializedKey); if (result != null) { return new ScalarKeyValueQueryResponse(base64Encode(valueSerde, result)); } else { throw new ScalarValueNotFoundException(String.format("Key %s not found in store %s", deserializedKey.toString(), abstractQuery.getStoreName())); } }); }
Example #15
Source File: AllKeyValuesQueryVerticleTest.java From kiqr with Apache License 2.0 | 6 votes |
@Test public void notFoundWithNoResult(TestContext context){ KafkaStreams streamMock = mock(KafkaStreams.class); ReadOnlyKeyValueStore<Object, Object> storeMock = mock(ReadOnlyKeyValueStore.class); KeyValueIterator<Object, Object> iteratorMock = mock(KeyValueIterator.class); when(streamMock.store(eq("store"), any(QueryableStoreType.class))).thenReturn(storeMock); SimpleKeyValueIterator iterator = new SimpleKeyValueIterator(); when(storeMock.all()).thenReturn(iterator); rule.vertx().deployVerticle(new AllKeyValuesQueryVerticle("host", streamMock), context.asyncAssertSuccess(deployment->{ StoreWideQuery query = new StoreWideQuery("store", Serdes.String().getClass().getName(), Serdes.String().getClass().getName()); rule.vertx().eventBus().send(Config.ALL_KEY_VALUE_QUERY_ADDRESS_PREFIX + "host", query, context.asyncAssertSuccess(reply ->{ context.assertTrue(reply.body() instanceof MultiValuedKeyValueQueryResponse); MultiValuedKeyValueQueryResponse response = (MultiValuedKeyValueQueryResponse) reply.body(); context.assertEquals(0, response.getResults().size()); context.assertTrue(iterator.closed); })); })); }
Example #16
Source File: RangeKeyValuesQueryVerticleTest.java From kiqr with Apache License 2.0 | 6 votes |
@Test public void notFoundWithNoResult(TestContext context){ KafkaStreams streamMock = mock(KafkaStreams.class); ReadOnlyKeyValueStore<Object, Object> storeMock = mock(ReadOnlyKeyValueStore.class); KeyValueIterator<Object, Object> iteratorMock = mock(KeyValueIterator.class); when(streamMock.store(eq("store"), any(QueryableStoreType.class))).thenReturn(storeMock); SimpleKeyValueIterator iterator = new SimpleKeyValueIterator(); when(storeMock.range(any(), any())).thenReturn(iterator); rule.vertx().deployVerticle(new RangeKeyValueQueryVerticle("host", streamMock), context.asyncAssertSuccess(deployment->{ RangeKeyValueQuery query = new RangeKeyValueQuery("store", Serdes.String().getClass().getName(), Serdes.String().getClass().getName(), "key".getBytes(), "key".getBytes()); rule.vertx().eventBus().send(Config.RANGE_KEY_VALUE_QUERY_ADDRESS_PREFIX + "host", query, context.asyncAssertSuccess(reply ->{ context.assertTrue(reply.body() instanceof MultiValuedKeyValueQueryResponse); MultiValuedKeyValueQueryResponse response = (MultiValuedKeyValueQueryResponse) reply.body(); context.assertEquals(0, response.getResults().size()); context.assertTrue(iterator.closed); })); })); }
Example #17
Source File: KafkaStreamsInteractiveQueryIntegrationTests.java From spring-cloud-stream-binder-kafka with Apache License 2.0 | 6 votes |
@Test public void testStateStoreRetrievalRetry() { StreamsBuilderFactoryBean mock = Mockito.mock(StreamsBuilderFactoryBean.class); KafkaStreams mockKafkaStreams = Mockito.mock(KafkaStreams.class); Mockito.when(mock.getKafkaStreams()).thenReturn(mockKafkaStreams); KafkaStreamsRegistry kafkaStreamsRegistry = new KafkaStreamsRegistry(); kafkaStreamsRegistry.registerKafkaStreams(mock); KafkaStreamsBinderConfigurationProperties binderConfigurationProperties = new KafkaStreamsBinderConfigurationProperties(new KafkaProperties()); binderConfigurationProperties.getStateStoreRetry().setMaxAttempts(3); InteractiveQueryService interactiveQueryService = new InteractiveQueryService(kafkaStreamsRegistry, binderConfigurationProperties); QueryableStoreType<ReadOnlyKeyValueStore<Object, Object>> storeType = QueryableStoreTypes.keyValueStore(); try { interactiveQueryService.getQueryableStore("foo", storeType); } catch (Exception ignored) { } Mockito.verify(mockKafkaStreams, times(3)).store("foo", storeType); }
Example #18
Source File: InteractiveQueries.java From quarkus-quickstarts with Apache License 2.0 | 5 votes |
private ReadOnlyKeyValueStore<Integer, Aggregation> getWeatherStationStore() { while (true) { try { return streams.store(TopologyProducer.WEATHER_STATIONS_STORE, QueryableStoreTypes.keyValueStore()); } catch (InvalidStateStoreException e) { // ignore, store not ready yet } } }
Example #19
Source File: KeyValueStoreGrpcImplLocalDispatcher.java From apicurio-registry with Apache License 2.0 | 5 votes |
@SuppressWarnings({"unchecked", "rawtypes"}) private <K, V> ExtReadOnlyKeyValueStore<K, V> keyValueStore(String storeName) { return (ExtReadOnlyKeyValueStore<K, V>) keyValueStores.computeIfAbsent( storeName, sn -> { QueryableStoreType<ReadOnlyKeyValueStore<K, V>> queryableStoreType = QueryableStoreTypes.keyValueStore(); StoreQueryParameters<ReadOnlyKeyValueStore<K, V>> sqp = StoreQueryParameters.fromNameAndType(storeName, queryableStoreType); return new ExtReadOnlyKeyValueStoreImpl( streams.store(sqp), filterPredicate ); } ); }
Example #20
Source File: StreamUtils.java From kafka-graphs with Apache License 2.0 | 5 votes |
public static <K, V> List<KeyValue<K, V>> listFromStore(KafkaStreams streams, String storeName) { final ReadOnlyKeyValueStore<K, V> store = streams.store( storeName, QueryableStoreTypes.keyValueStore()); try (final KeyValueIterator<K, V> all = store.all()) { List<KeyValue<K, V>> result = new ArrayList<>(); while (all.hasNext()) { result.add(all.next()); } return result; } }
Example #21
Source File: StreamUtils.java From kafka-graphs with Apache License 2.0 | 5 votes |
public static <K, V> NavigableMap<K, V> mapFromStore(KafkaStreams streams, String storeName) { final ReadOnlyKeyValueStore<K, V> store = streams.store( storeName, QueryableStoreTypes.keyValueStore()); try (final KeyValueIterator<K, V> all = store.all()) { NavigableMap<K, V> result = new TreeMap<>(); while (all.hasNext()) { KeyValue<K, V> next = all.next(); result.put(next.key, next.value); } return result; } }
Example #22
Source File: TopScorersBuilderTest.java From football-events with MIT License | 5 votes |
@Test public void testTopPlayers() { tester.send(getClass().getResource("player-goals.json"), PlayerGoals.class, Topics.viewTopicName(PlayerGoals.class), PlayerGoals::getPlayerId); ReadOnlyKeyValueStore<String, TopPlayers> store = tester.getStore(TopScorersBuilder.TOP_SCORERS_STORE); List<PlayerGoals> players = store.get("topPlayers").getPlayers(); assertThat(players.get(0).getGoals()).isEqualTo(5); assertThat(players.get(1).getGoals()).isEqualTo(4); assertThat(players.get(2).getGoals()).isEqualTo(2); assertThat(players.get(3).getGoals()).isEqualTo(1); }
Example #23
Source File: SnapshotBuilderTest.java From football-events with MIT License | 5 votes |
@Test public void test() throws Exception { tester.sendEvents(getClass().getResource("player-started-career.json"), PlayerStartedCareer.class); ReadOnlyKeyValueStore<String, Player> playerStore = tester.getStore(DomainUpdater.PLAYER_STORE); assertThat(tester.count(playerStore)).isEqualTo(4); assertThat(playerStore.get("2").getName()).isEqualTo("James Henry"); }
Example #24
Source File: StatisticsBuilderTest.java From football-events with MIT License | 5 votes |
@Test public void testMatchStatistics() { tester.sendEvents(getClass().getResource("player-started-career.json"), PlayerStartedCareer.class); tester.sendEvents(getClass().getResource("match-started.json"), MatchStarted.class); tester.sendEvents(getClass().getResource("goal-scored.json"), GoalScored.class); tester.sendEvents(getClass().getResource("match-finished.json"), MatchFinished.class); ReadOnlyKeyValueStore<String, MatchScore> matchStore = tester.getStore(MATCH_SCORES_STORE); ReadOnlyKeyValueStore<String, TeamRanking> rankingStore = tester.getStore(TEAM_RANKING_STORE); assertThat(tester.count(rankingStore)).isEqualTo(24); assertThat(tester.count(matchStore)).isEqualTo(22); MatchScore brentfordVsNottinghamForest = matchStore.get("15"); assertThat(brentfordVsNottinghamForest.getHomeGoals()).isEqualTo(3); assertThat(brentfordVsNottinghamForest.getAwayGoals()).isEqualTo(4); MatchScore leedsUnitedVsPrestonNorthEnd = matchStore.get("19"); assertThat(leedsUnitedVsPrestonNorthEnd.getHomeGoals()).isEqualTo(0); assertThat(leedsUnitedVsPrestonNorthEnd.getAwayGoals()).isEqualTo(0); TeamRanking nottinghamForest = rankingStore.get("Nottingham Forest"); assertThat(nottinghamForest.getMatchesPlayed()).isEqualTo(2); assertThat(nottinghamForest.getGoalsFor()).isEqualTo(5); assertThat(nottinghamForest.getGoalsAgainst()).isEqualTo(3); assertThat(nottinghamForest.getPoints()).isEqualTo(6); TeamRanking burtonAlbion = rankingStore.get("Burton Albion"); assertThat(burtonAlbion.getMatchesPlayed()).isEqualTo(2); assertThat(burtonAlbion.getGoalsFor()).isEqualTo(1); assertThat(burtonAlbion.getGoalsAgainst()).isEqualTo(5); assertThat(burtonAlbion.getPoints()).isEqualTo(0); }
Example #25
Source File: StatisticsBuilderTest.java From football-events with MIT License | 5 votes |
@Test public void testPlayerStatistics() { tester.sendEvents(getClass().getResource("player-started-career.json"), PlayerStartedCareer.class); tester.sendEvents(getClass().getResource("goal-scored.json"), GoalScored.class); tester.sendEvents(getClass().getResource("card-received.json"), CardReceived.class); ReadOnlyKeyValueStore<String, PlayerGoals> goalsStore = tester.getStore(PLAYER_GOALS_STORE); ReadOnlyKeyValueStore<String, PlayerCards> cardsStore = tester.getStore(PLAYER_CARDS_STORE); PlayerGoals bBradleyJohnsonGoals = goalsStore.get("B. Bradley Johnson"); assertThat(bBradleyJohnsonGoals.getGoals()).isEqualTo(1); assertThat(cardsStore.get("B. Bradley Johnson")).isNull(); PlayerGoals aAndreasBouchalakisGoals = goalsStore.get("A. Andreas Bouchalakis"); PlayerCards aAndreasBouchalakisCards = cardsStore.get("A. Andreas Bouchalakis"); assertThat(aAndreasBouchalakisGoals.getGoals()).isEqualTo(2); assertThat(aAndreasBouchalakisCards.getYellowCards()).isEqualTo(3); assertThat(aAndreasBouchalakisCards.getRedCards()).isEqualTo(0); PlayerCards jJamesVaughanCards = cardsStore.get("J. James Vaughan"); assertThat(jJamesVaughanCards.getYellowCards()).isEqualTo(1); assertThat(jJamesVaughanCards.getRedCards()).isEqualTo(0); assertThat(goalsStore.get("J. James Vaughan")).isNull(); PlayerCards dDarylMurphyCards = cardsStore.get("D. Daryl Murphy"); PlayerGoals dDarylMurphyGoals = goalsStore.get("D. Daryl Murphy"); assertThat(dDarylMurphyGoals.getGoals()).isEqualTo(1); assertThat(dDarylMurphyCards.getYellowCards()).isEqualTo(0); assertThat(dDarylMurphyCards.getRedCards()).isEqualTo(1); }
Example #26
Source File: DomainUpdaterTest.java From football-events with MIT License | 5 votes |
@Test public void test() throws Exception { tester.sendEvents(getClass().getResource("player-started-career.json"), PlayerStartedCareer.class); tester.sendEvents(getClass().getResource("match-scheduled.json"), MatchScheduled.class); tester.sendEvents(getClass().getResource("match-started.json"), MatchStarted.class); tester.sendEvents(getClass().getResource("goal-scored.json"), GoalScored.class); tester.sendEvents(getClass().getResource("card-received.json"), CardReceived.class); tester.sendEvents(getClass().getResource("match-finished.json"), MatchFinished.class); ReadOnlyKeyValueStore<String, Match> matchStore = tester.getStore(DomainUpdater.MATCH_STORE); ReadOnlyKeyValueStore<String, Player> playerStore = tester.getStore(DomainUpdater.PLAYER_STORE); assertThat(tester.count(playerStore)).isEqualTo(4); assertThat(playerStore.get("3").getName()).isEqualTo("Lewis McGugan"); assertThat(tester.count(matchStore)).isEqualTo(4); Match match1 = matchStore.get("1"); Match match2 = matchStore.get("2"); Match match3 = matchStore.get("3"); Match match4 = matchStore.get("4"); assertThat(match1.getState()).isEqualTo(Match.State.FINISHED); assertThat(match2.getState()).isEqualTo(Match.State.STARTED); assertThat(match3.getState()).isEqualTo(Match.State.STARTED); assertThat(match4.getState()).isEqualTo(Match.State.SCHEDULED); assertThat(match1.getHomeGoals().size()).isEqualTo(1); assertThat(match1.getAwayGoals().size()).isEqualTo(1); assertThat(match2.getHomeGoals().size()).isEqualTo(1); assertThat(match2.getAwayGoals().size()).isEqualTo(0); assertThat(match3.getHomeGoals().size()).isEqualTo(3); assertThat(match3.getAwayGoals().size()).isEqualTo(1); assertThat(match4.getHomeGoals().size()).isEqualTo(0); assertThat(match4.getAwayGoals().size()).isEqualTo(0); assertThat(match1.getCards().size()).isEqualTo(1); assertThat(match2.getCards().size()).isEqualTo(1); }
Example #27
Source File: VehicleQueryService.java From microservice-patterns with Apache License 2.0 | 5 votes |
@GetMapping("/count/{status}") public long getVehicleCoutnForStatus(@PathVariable("status") String status) { // Get the state-store ReadOnlyKeyValueStore<String, Long> keyValueStore= kStreamBuilderFactoryBean.getKafkaStreams() .store("statusCount", QueryableStoreTypes.keyValueStore()); return keyValueStore.get(status); //get the count for the key viz. Offline/Online }
Example #28
Source File: KafkaStreamsEndpoint.java From quarkus with Apache License 2.0 | 5 votes |
private ReadOnlyKeyValueStore<Integer, Long> getCountstore() { while (true) { try { return streams.store("countstore", QueryableStoreTypes.keyValueStore()); } catch (InvalidStateStoreException e) { // ignore, store not ready yet } } }
Example #29
Source File: KafkaStreamsInteractiveQueryIntegrationTests.java From spring-cloud-stream-binder-kafka with Apache License 2.0 | 5 votes |
public Long getProductStock(Integer id) { ReadOnlyKeyValueStore<Object, Object> keyValueStore = interactiveQueryService .getQueryableStore("prod-id-count-store", QueryableStoreTypes.keyValueStore()); return (Long) keyValueStore.get(id); }
Example #30
Source File: KafkaStreamsAggregateSample.java From spring-cloud-stream-samples with Apache License 2.0 | 5 votes |
@RequestMapping("/events") public String events() { final ReadOnlyKeyValueStore<String, String> topFiveStore = interactiveQueryService.getQueryableStore("test-events-snapshots", QueryableStoreTypes.<String, String>keyValueStore()); return topFiveStore.get("12345"); }