What's the way of running KSQL from spring boot app

Viewed 4253

I have a spring boot application that is connected to a kafka cluster. How can I run KSQL from java code?

2 Answers

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

Related