Java Code Examples for org.apache.kafka.streams.Topology#addStateStore()
The following examples show how to use
org.apache.kafka.streams.Topology#addStateStore() .
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: StreamsUtils.java From football-events with MIT License | 5 votes |
public static <D, E extends Event> void addStore(Topology topology, Class<D> domainType, String store, Class<E>... eventTypes) { StoreBuilder<KeyValueStore<String, D>> matchStoreBuilder = Stores.keyValueStoreBuilder( Stores.persistentKeyValueStore(store), Serdes.String(), new JsonPojoSerde<D>(domainType)) .withLoggingDisabled(); String[] processorNames = Stream.of(eventTypes) .map(event -> event.getSimpleName() + "Process") .collect(Collectors.toList()).toArray(new String[eventTypes.length]); topology.addStateStore(matchStoreBuilder, processorNames); }
Example 2
Source File: StockFeedApp.java From Kafka-Streams-Real-time-Stream-Processing with The Unlicense | 4 votes |
public static void main(String[] args) { Properties props = new Properties(); props.put(StreamsConfig.APPLICATION_ID_CONFIG, AppConfigs.applicationID); props.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, AppConfigs.bootstrapServers); props.put(StreamsConfig.STATE_DIR_CONFIG, AppConfigs.stateStoreLocation); Topology topology = new Topology(); topology.addSource( AppConfigs.sourceName, AppSerdes.String().deserializer(), AppSerdes.StockTicker().deserializer(), AppConfigs.sourceTopicName); topology.addProcessor( StockProcessor.PROCESSOR_NAME, () -> new StockProcessor(), AppConfigs.sourceName); StoreBuilder storeBuilder = Stores.keyValueStoreBuilder( Stores.persistentKeyValueStore(StockProcessor.STATE_STORE_NAME), AppSerdes.String(), AppSerdes.TickerStack() ); topology.addStateStore( storeBuilder, StockProcessor.PROCESSOR_NAME); topology.addSink(AppConfigs.sinkName, AppConfigs.targetTopicName, AppSerdes.String().serializer(), AppSerdes.StockTicker().serializer(), StockProcessor.PROCESSOR_NAME); KafkaStreams streams = new KafkaStreams(topology, props); streams.start(); Runtime.getRuntime().addShutdownHook(new Thread(streams::close)); }