问题
I have a spring boot application that is connected to a kafka cluster. How can I run KSQL from java code?
回答1:
At the moment, there is no direct way to use KSQL as a library in java. There is an open issue#734 for the same.
But you can run the KSQL statement using REST API and that implementation can be done in Spring Boot Application. A Rest call would look something like this:
POST /query HTTP/1.1
Accept: application/vnd.ksql.v1+json
Content-Type: application/vnd.ksql.v1+json
{
"ksql": "SELECT * FROM pageviews;",
"streamsProperties": {
"ksql.streams.auto.offset.reset": "earliest"
}
}
// Through Curl
curl -X "POST" "http://localhost:8088/ksql" \
-H "Content-Type: application/vnd.ksql.v1+json; charset=utf-8" \
-d $'{
"ksql": "LIST STREAMS;",
"streamsProperties": {}
}'
You can find the documentation here :
https://docs.confluent.io/current/ksql/docs/developer-guide/api.html#rest-endpoint
回答2:
Since ksqlDB 0.10 there is now a Java client: https://docs.ksqldb.io/en/latest/developer-guide/ksqldb-clients/java-client/
来源:https://stackoverflow.com/questions/54102221/whats-the-way-of-running-ksql-from-spring-boot-app