【问题标题】:Kafka Ktable queryingKafka Ktable 查询
【发布时间】:2018-04-18 10:50:34
【问题描述】:

尝试通过 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() 始终为空。为什么哪里没有可供查询的商店?我看到诸如“test_connect-configs_12-connect-configsSTATE-STORE-0000000000-changelog”之类的主题。如何读取记录以及如何获取 KTable 状态的更改事件?

【问题讨论】:

    标签: apache-kafka-streams


    【解决方案1】:

    创建KTable时需要指定底层存储的名称:

    builder.table("connect-configs", Materialized.as<...>("my-store-name"));
    

    【讨论】:

      猜你喜欢
      • 2020-01-30
      • 1970-01-01
      • 2017-08-13
      • 2020-04-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-04
      • 2021-01-21
      相关资源
      最近更新 更多