Skip to content
Advertisement

KsqlClientException: Received 401 response from server: Unauthorized. Error code: 40100

Trying to connect to Confluent hosted KSQL db.

    String username = API_KEY;      
    String password = API_SECRET;
    
    String CONFLUENT_CLOUD_HOST = "pksqlc-xxxxx.us-east-2.aws.confluent.cloud";
    
    ClientOptions options = ClientOptions.create()
            .setHost(CONFLUENT_CLOUD_HOST)
            .setPort(443)
            .setBasicAuthCredentials(username, password)
            .setUseTls(true)
            .setUseAlpn(true)
            ;
    Client client = Client.create(options);

    List<StreamInfo> streams = client.listStreams().get();

And i get an exception during client.listStreams().get():

Exception in thread "main" java.util.concurrent.ExecutionException: io.confluent.ksql.api.client.exception.KsqlClientException: Received 401 response from server: Unauthorized. Error code: 40100
   at java.base/java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:395)
   at java.base/java.util.concurrent.CompletableFuture.get(CompletableFuture.java:1999)

What am i missing here?

Advertisement

Answer

Did you check the API_KEY/API_SECRET on your Confluent Cloud cluster to see if it is granted access to KSQLDB?

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement