Kafka KTable查询

3
尝试通过KTable从“connect-configs”主题获取记录。
    public static void main(String...  args) throws InterruptedException {
    Properties config = new Properties();
    config.put(StreamsConfig.APPLICATION_ID_CONFIG, "test_connect-configs_12");

    config.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, "***:9092");
    config.put(StreamsConfig.DEFAULT_KEY_SERDE_CLASS_CONFIG, Serdes.String().getClass());
    config.put(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG,Serdes.Bytes().getClass());
    config.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
    StreamsBuilder builder = new StreamsBuilder();
    KTable<String, Object> ktable = builder.table("connect-configs");
    KafkaStreams streams = new KafkaStreams(builder.build(),config);
    streams.cleanUp();
    streams.start();
    System.out.println(ktable.queryableStoreName());
    Runtime.getRuntime().addShutdownHook(new Thread(streams::close));
    ReadOnlyKeyValueStore<String, Object> view;
    while (true) {
        try {
             System.out.println(ktable.queryableStoreName());
             view = streams.store(ktable.queryableStoreName(), QueryableStoreTypes.keyValueStore());

        } catch (InvalidStateStoreException ignored) {
          // store not yet ready for querying
          Thread.sleep(100);
        }
      }


};

ktable.queryableStoreName() 总是 null。为什么没有用于查询的存储?我看到了像“test_connect-configs_12-connect-configsSTATE-STORE-0000000000-changelog”这样的主题。我应该如何读取记录以及如何获取KTable状态的更改事件?

1个回答

7
创建 KTable 时,需要为底层存储指定名称:
builder.table("connect-configs", Materialized.as<...>("my-store-name"));

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接