KSQLDb java client giving error while connecting -This endpoint is only available when using HTTP2

573 views
Skip to first unread message

Venkatesh M

unread,
Aug 25, 2020, 11:00:07 AM8/25/20
to ksqldb-users

I am using 0.11.0 version ksqldb , while connecting ksldb through java client using domainname ( ex : dev.host) with port 80 I am getting below error , but with same url I am able connect through cli .

"java.util.concurrent.ExecutionException: io.confluent.ksql.api.client.exception.KsqlClientException: Received 400 response from server: This endpoint is only available when using HTTP2. Error code: 40004"

Please help me how to resolve this issue.

Thanks

Victoria Xia

unread,
Aug 25, 2020, 12:08:39 PM8/25/20
to ksqldb-users
Hi,

Can you please share your ksqlDB Java client code, including the method that returned that error and also how you created the client?

Thanks,
Victoria

Venkatesh M

unread,
Aug 25, 2020, 8:41:09 PM8/25/20
to Victoria Xia, ksqldb-users
HI,


I am getting error at the line/code   which highlighted in  red below class .
            streamedQueryResult=client.streamQuery("select companyid from teststream emit changes limit 1;").get();
public class Ksql {


public static String KSQLDB_SERVER_HOST ="sample.net";
public static int KSQLDB_SERVER_HOST_PORT = 80;
public static void main(String[] args) {
ClientOptions options = ClientOptions.create()
.setHost(
KSQLDB_SERVER_HOST)
.setPort(
KSQLDB_SERVER_HOST_PORT);

options.setVerifyHost(true);
System.out.println(" stream query started before ");
Client client = Client.create(options);
System.out.println(" stream query started after connection"+client);
// Send requests with the client by following the other examples
StreamedQueryResult streamedQueryResult = null;
try {
streamedQueryResult=client.streamQuery("select companyid from teststream emit changes limit 1;").get();
} catch (InterruptedException e) {
e.printStackTrace();
}
catch (ExecutionException e) {

e.printStackTrace();
}

// Block until a new row is available
// System.out.println(" query is completed "+streamedQueryResult.isComplete());

Row row = streamedQueryResult.poll();

while(row!=null) {
List<String> list = row.columnNames();
System.out.println(" columns " + list);
System.out.println("Received a row!");
System.out.println("Row: " + row.getValue("COMPANYID"));
row = streamedQueryResult.poll();
}
client.close();
// Terminate any open connections and close the clientclient.close();
}
}

Stack strace for reference:

java.util.concurrent.ExecutionException: io.confluent.ksql.api.client.exception.KsqlClientException: Received 400 response from server: This endpoint is only available when using HTTP2. Error code: 40004
at java.base/java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:395)
at java.base/java.util.concurrent.CompletableFuture.get(CompletableFuture.java:1999)
at org.example.Ksql.main(Ksql.java:30)
Caused by: io.confluent.ksql.api.client.exception.KsqlClientException: Received 400 response from server: This endpoint is only available when using HTTP2. Error code: 40004
at io.confluent.ksql.api.client.impl.ClientImpl.lambda$handleErrorResponse$16(ClientImpl.java:436)
at io.vertx.core.http.impl.HttpClientResponseImpl$BodyHandler.notifyHandler(HttpClientResponseImpl.java:292)
at io.vertx.core.http.impl.HttpClientResponseImpl.lambda$bodyHandler$0(HttpClientResponseImpl.java:193)
at io.vertx.core.http.impl.HttpClientResponseImpl.handleEnd(HttpClientResponseImpl.java:248)
at io.vertx.core.http.impl.Http2ClientConnection$Http2ClientStream.handleEnd(Http2ClientConnection.java:260)
at io.vertx.core.http.impl.VertxHttp2Stream.lambda$new$1(VertxHttp2Stream.java:68)
at io.vertx.core.streams.impl.InboundBuffer.handleEvent(InboundBuffer.java:237)
at io.vertx.core.streams.impl.InboundBuffer.write(InboundBuffer.java:127)
at io.vertx.core.http.impl.VertxHttp2Stream.onEnd(VertxHttp2Stream.java:107)
at io.vertx.core.http.impl.VertxHttp2Stream.onEnd(VertxHttp2Stream.java:100)
at io.vertx.core.http.impl.Http2ConnectionBase.lambda$onDataRead$10(Http2ConnectionBase.java:333)
at io.vertx.core.impl.ContextImpl.executeTask(ContextImpl.java:366)
at io.vertx.core.impl.EventLoopContext.execute(EventLoopContext.java:43)
at io.vertx.core.impl.ContextImpl.executeFromIO(ContextImpl.java:229)
at io.vertx.core.impl.ContextImpl.executeFromIO(ContextImpl.java:221)
at io.vertx.core.http.impl.Http2ConnectionBase.onDataRead(Http2ConnectionBase.java:333)
at io.netty.handler.codec.http2.Http2FrameListenerDecorator.onDataRead(Http2FrameListenerDecorator.java:36)
at io.netty.handler.codec.http2.Http2EmptyDataFrameListener.onDataRead(Http2EmptyDataFrameListener.java:49)
at io.netty.handler.codec.http2.DefaultHttp2ConnectionDecoder$FrameReadListener.onDataRead(DefaultHttp2ConnectionDecoder.java:292)
at io.netty.handler.codec.http2.DefaultHttp2FrameReader.readDataFrame(DefaultHttp2FrameReader.java:422)
at io.netty.handler.codec.http2.DefaultHttp2FrameReader.processPayloadState(DefaultHttp2FrameReader.java:251)
at io.netty.handler.codec.http2.DefaultHttp2FrameReader.readFrame(DefaultHttp2FrameReader.java:160)
at io.netty.handler.codec.http2.DefaultHttp2ConnectionDecoder.decodeFrame(DefaultHttp2ConnectionDecoder.java:174)
at io.netty.handler.codec.http2.DecoratingHttp2ConnectionDecoder.decodeFrame(DecoratingHttp2ConnectionDecoder.java:63)
at io.netty.handler.codec.http2.Http2ConnectionHandler$FrameDecoder.decode(Http2ConnectionHandler.java:378)
at io.netty.handler.codec.http2.Http2ConnectionHandler.decode(Http2ConnectionHandler.java:438)
at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:498)
at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:437)
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:276)
at io.vertx.core.http.impl.VertxHttp2ConnectionHandler.channelRead(VertxHttp2ConnectionHandler.java:418)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:714)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:650)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:576)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.base/java.lang.Thread.run(Thread.java:834)


Thanks
Venkatesh M

--
You received this message because you are subscribed to a topic in the Google Groups "ksqldb-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ksql-users/8srNdOGj76Q/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ksql-users+...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/ksql-users/9bf3c154-24d2-4e49-8d74-76c9b3dc3e7cn%40googlegroups.com.

Victoria Xia

unread,
Aug 25, 2020, 11:04:54 PM8/25/20
to ksqldb-users
Hi Venkatesh,

This error is very curious since the Java client for ksqlDB is configured to always use HTTP/2, so I'm not sure why the request is being sent via a different HTTP version.

Can you try hitting the endpoint that the client uses with a curl request? The command you should use is
curl --http2 -X POST "http://sample.net:80/query-stream" -H "Content-Type: application/json; charset=utf-8" -d '{"sql":"select  companyid  from teststream emit changes limit 1;"}'

Or, if you want to stream results from the beginning of time (rather than only newly arriving result rows):
curl --http2 -X POST "http://sample.net:80/query-stream" -H "Content-Type: application/json; charset=utf-8" -d '{"sql":"select  companyid  from teststream emit changes limit 1;","properties":{"auto.offset.reset":"earliest"}}'

This will help narrow whether the problem is on the server side (e.g., server configurations) or on the client side.

(In case you're curious, the reason we have to use curl rather than the ksqlDB CLI as you mentioned previously is because the CLI uses a different endpoint from the Java client. Specifically, the CLI uses the /query endpoint whereas the Java client uses the /query-stream endpoint.)

Best,
Victoria

kumar....@gmail.com

unread,
Oct 27, 2020, 3:04:54 PM10/27/20
to ksqldb-users
Hi  Victoria,

Through java client for "/query-stream" api(streamQuery()), I'm also facing same error i.e. "Received 400 response from server: This endpoint is only available when using HTTP2. Error code: 40004"

Also tried through curl command, hitting with similar error

Command:
curl -X "POST" "https://ksql.k8s.com:443/query-stream" --http2 -H "Content-Type: application/json; charset=utf-8" -d $'{ "ksql": "SELECT * FROM EVENTS EMIT CHANGES;", "streamsProperties": {"ksql.streams.auto.offset.reset": "earliest"} }' | jq . 
 
Curl output :

{
 "@type": "generic_error",
 "error_code": 40004,
 "message": "This endpoint is only available when using HTTP2"
}  

I mean any specific configuration do we have to take care at server side ? However push/pull queries working as expected through ksqldb-cli client.

Java Environment Details :

ksqlDB : 0.12.0
JDK: Zulu 11


Regards,
Subash 

Victoria Xia

unread,
Oct 28, 2020, 11:56:50 AM10/28/20
to ksqldb-users
Hi Subash,

The body of your HTTP request is incorrectly formatted: the payload fields should be "sql" and "properties", not "ksql" and "streamsProperties". Here is the relevant documentation: https://docs.ksqldb.io/en/latest/developer-guide/ksqldb-rest-api/streaming-endpoint/

If you fix the request body and still continue to see the same issue, can you please file a GitHub issue so the team can take a closer look? In addition to the information you've shared here, it'd also be helpful to understand how your ksqlDB server is deployed, and to get a full Java client code snippet in order to reproduce the problem.

Thanks,
Victoria

Subash Parida

unread,
Nov 3, 2020, 4:11:02 AM11/3/20
to Victoria Xia, ksqldb-users
I tried all the way.. but no luck.

Will create a github issue for closer look.

Thanks,
Subash

You received this message because you are subscribed to the Google Groups "ksqldb-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ksql-users+...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/ksql-users/29d8a25c-2ebc-40eb-b6ec-b0f25bb4f134n%40googlegroups.com.

kumar....@gmail.com

unread,
Nov 3, 2020, 8:51:29 AM11/3/20
to ksqldb-users
created one, link to the issue : https://github.com/confluentinc/ksql/issues/6560 
Reply all
Reply to author
Forward
0 new messages