我的代码当前正在使用InMemoryKeyValueStore,这避免了对磁盘或kafka的持久性。 我想使用rocksdb(Stores.persistentKeyValueStore),以便该应用程序将从磁盘重新加载状态。我正在尝试实现这一点,而我对Kafka和streams API还是很陌生。在我仍在尝试理解事物的同时,希望能对我如何进行更改提供帮助。
我试图在这里创建状态存储:
StoreBuilder<KeyValueStore<String, LinkedList<StoreItem>>> store =
Stores.<String, LinkedList<StoreItem>>keyValueStoreBuilder(Stores.persistentKeyValueStore(storeKey), Serdes.String(), valueSerde);
如何在流构建器中注册它?
使用inMemoryKeyValueStore的现有代码:
static StoreBuilder<KeyValueStore<String, LinkedList<StoreItem>>> makeStoreBuilder(
final String storeKey,
final Serde<LinkedList<StoreItem>> valueSerde,
final boolean loggingDisabled) {
final StoreBuilder<KeyValueStore<String, LinkedList<StoreItem>>> storeBuilder =
Stores.keyValueStoreBuilder(Stores.inMemoryKeyValueStore(storeKey), Serdes.String(), valueSerde);
return storeBuilder;
}
我需要确保每次重启后,流应用程序都不会最终丢失日志主题中的现有消息。
答案 0 :(得分:0)
如何在流构建器中注册它?
通过致电StreamsBuilder#addStateStore()
。
有关端到端演示应用程序,请参见https://github.com/confluentinc/kafka-streams-examples的StateStoresInTheDSLIntegrationTest
。
答案 1 :(得分:0)
您将永久存储完全用作内存存储。商店负责其余的工作,您无需担心加载数据等问题。您只需使用它即可。