0

I have this method which input's a JSON payload. I want to create a K-table out of this payload, read the data out of it and print it.

So far, I am to create the KTable, but when I iterate over it, the control skips over it.

Please can anyone help me/guide me where am I going wrong or what I am I missing?

Thanks.

 public void twilioKTable(JsonNode payloadJson) throws JsonProcessingException {
        String payload = payloadJson.toString();
        final StreamsBuilder builder = new StreamsBuilder();
        final KTable<String, String> kTable = builder.table("testktable");

        kTable.toStream().map((key, value) -> new KeyValue<>(key, value))
                .foreach(new ForeachAction<String, String>() {
                    public void apply(String key, String value) {
                        System.out.println("From MAP " + key + ": Value " +
                                value);
                    }
                });
    }
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
anmol
  • 1
  • [KStreams have a `.print()` method that you can use instead](https://stackoverflow.com/questions/39327868/print-kafka-stream-input-out-to-console) – OneCricketeer Jul 23 '21 at 22:54
  • @OneCricketeer Is it necessary to convert to KStream? In a normal Database, we can read the table data using the primary key. Can something be done like that, here? – anmol Jul 24 '21 at 04:21
  • If you have acess to the KeyValueStore (which is not possible with the DSL methods), you can iterate it. Otherwise, sounds like you want ksqlDB instead – OneCricketeer Jul 25 '21 at 16:24

1 Answers1

1

You could also use .peek() method in KStream to print every key with value

Jacek Sawko
  • 190
  • 2
  • 7