2

I am using confluent kafka version 6.o downloaded from https://www.confluent.io/download/

I am referring

  1. https://docs.ksqldb.io/en/latest/developer-guide/ksqldb-clients/java-client/ acritical .
  2. https://www.youtube.com/watch?v=85udigshlNI

with java producer code I am able to send value to ksql. But not able to retrieve this value. when I am printing log for streamQuery result, I am getting Not Completed message.

used Maven dependency as:

<dependencies>
        <dependency>
            <groupId>io.confluent.ksql</groupId>
            <artifactId>ksqldb-api-client</artifactId>
            <version>${ksqldb.version}</version>
        </dependency>
    </dependencies>

java code :

 public class ExampleApp {
    
      public static String KSQLDB_SERVER_HOST = "localhost";
      public static int KSQLDB_SERVER_HOST_PORT = 8088;
    
      public static void main(String[] args) {
        ClientOptions options = ClientOptions.create()
            .setHost(KSQLDB_SERVER_HOST)
            .setPort(KSQLDB_SERVER_HOST_PORT);
        Client client = Client.create(options);
    
        // Send requests with the client by following the other examples
    
        // Terminate any open connections and close the client
        client.close();
      }
    }public class ExampleApp {
    
      public static String KSQLDB_SERVER_HOST = "localhost";
      public static int KSQLDB_SERVER_HOST_PORT = 8088;
    
      public static void main(String[] args) {
        ClientOptions options = ClientOptions.create()
            .setHost(KSQLDB_SERVER_HOST)
            .setPort(KSQLDB_SERVER_HOST_PORT);
        Client client = Client.create(options);
    
        StreamedQueryResult streamedQueryResult = client.streamQuery("SELECT * FROM MY_STREAM EMIT CHANGES;").get();
    
    for (int i = 0; i < 10; i++) {
      // Block until a new row is available
      Row row = streamedQueryResult.poll();
      if (row != null) {
        System.out.println("Received a row!");
        System.out.println("Row: " + row.values());
      } else {
        System.out.println("Query has ended.");
      }
    }
        client.close();
      }
    }

output : get() is waiting for long time even after adding values into topic waiting and finally gives timeout exception.

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
raj
  • 31
  • 4

0 Answers0