forked from mitch-seymour/mastering-kafka-streams-and-ksqldb
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add reactive programing api endpoint
- Loading branch information
1 parent
2969a40
commit 40d5869
Showing
9 changed files
with
380 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 0 additions & 22 deletions
22
...04/video-game-leaderboard-spring/src/main/java/com/magicalpipelines/KStreamProcessor.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
.../video-game-leaderboard-spring/src/main/java/com/magicalpipelines/api/KafkaComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.magicalpipelines.api; | ||
|
||
import org.apache.kafka.streams.KafkaStreams; | ||
import org.apache.kafka.streams.StoreQueryParameters; | ||
import org.apache.kafka.streams.state.QueryableStoreTypes; | ||
import org.apache.kafka.streams.state.ReadOnlyKeyValueStore; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.cloud.stream.binder.kafka.streams.InteractiveQueryService; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.kafka.config.StreamsBuilderFactoryBean; | ||
import org.springframework.stereotype.Component; | ||
|
||
import com.magicalpipelines.HighScores; | ||
|
||
@Component | ||
public class KafkaComponent { | ||
@Autowired | ||
private InteractiveQueryService interactiveQueryService; | ||
@Autowired | ||
private ApplicationContext context; | ||
protected KafkaStreams getStream() { | ||
String[] clazzNames = context.getBeanNamesForType( StreamsBuilderFactoryBean.class); | ||
for(String name:clazzNames) { | ||
System.out.println(name); | ||
} | ||
final StreamsBuilderFactoryBean streamsBuilderFactoryBean = | ||
context.getBean("&stream-builder-jointProducts", StreamsBuilderFactoryBean.class); | ||
|
||
KafkaStreams kafkaStreams = streamsBuilderFactoryBean.getKafkaStreams(); | ||
return kafkaStreams ; | ||
} | ||
|
||
protected ReadOnlyKeyValueStore<String, HighScores> getStore() { | ||
int tmp =(int)(Math.random()*10000); | ||
|
||
if ( (tmp % 2) == 0) | ||
return getStoreV1(); | ||
else | ||
return getStoreV2(); | ||
} | ||
|
||
protected ReadOnlyKeyValueStore<String, HighScores> getStoreV1() { | ||
return interactiveQueryService.getQueryableStore( | ||
// state store name | ||
"leader-boards", | ||
// state store type | ||
QueryableStoreTypes.keyValueStore()); | ||
} | ||
|
||
protected ReadOnlyKeyValueStore<String, HighScores> getStoreV2() { | ||
|
||
return getStream().store(StoreQueryParameters.fromNameAndType( | ||
// state store name | ||
"leader-boards", | ||
// state store type | ||
QueryableStoreTypes.keyValueStore())); | ||
} | ||
} |
Oops, something went wrong.