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

回眸只為那壹抹淺笑 提交于 2020-12-22 19:45:33

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!