I'm developing a simple Java app, which tries to pull data from ksqldb using Java client.
Below is the code, but StreamedQueryResult streamedQueryResult = client.streamQuery(pullQuery).get();
forever going in block state.
public class ExampleApp {
public static String KSQLDB_SERVER_HOST = "0.0.0.0";
public static int KSQLDB_SERVER_HOST_PORT = 8088;
public static void main(String[] args) throws ExecutionException, InterruptedException {
Map<String, Object> properties = Collections.singletonMap(
"auto.offset.reset", "earliest"
);
ClientOptions options = ClientOptions.create()
.setHost(KSQLDB_SERVER_HOST)
.setPort(KSQLDB_SERVER_HOST_PORT)
.setUseTls(false)
.setUseAlpn(true);
Client client = Client.create(options);
String pullQuery = "select name, countrycode from USERS_STREAM emit changes;";
StreamedQueryResult streamedQueryResult = client.streamQuery(pullQuery).get();
Row row = streamedQueryResult.poll();
System.out.println("## "+ row.values());
}
}
I've created topic:
kafka-topics --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic USERS
Created topic USERS.
kafka-console-producer --bootstrap-server localhost:9092 --topic USERS
>Alice,US
>John,SL
>Prateek,IND
>Mike,GB
>Zoran,GB
>Rani,Ind
>Vlad,PL
>
Also, I created users_stream, hope this is good setup to start the code.
ksql> create stream users_stream (name VARCHAR, countrycode VARCHAR) WITH (KAFKA_TOPIC='USERS', VALUE_FORMAT='DELIMITED');
Message
----------------
Stream created
----------------
ksql> select name, countrycode from USERS_STREAM emit changes;
+-----------------------------------------------------------------+-----------------------------------------------------------------+
|NAME |COUNTRYCODE |
+-----------------------------------------------------------------+-----------------------------------------------------------------+
|Prateek |IND |
|Mike |GB |
|Zoran |GB |
|Rani |Ind |
^CQuery terminated
I used confluent platform setup locally to start the confluent kafka
confluent local services start
The local commands are intended for a single-node development environment only,
NOT for production usage. https://docs.confluent.io/current/cli/index.html
Using CONFLUENT_CURRENT: /var/folders/kn/4wr9__651l37hckxvnnwt4hh0000gn/T/confluent.439906
Starting ZooKeeper
ZooKeeper is [UP]
Starting Kafka
Kafka is [UP]
Starting Schema Registry
Schema Registry is [UP]
Starting Kafka REST
Kafka REST is [UP]
Starting Connect
Connect is [UP]
Starting ksqlDB Server
ksqlDB Server is [UP]
Starting Control Center
Control Center is [UP]