Unable to connect to Kafka broker from K6

I am trying to connect my Kafka which is protected by api-key for K6 runs. The original documentation on K6 website doesn’t point on how to connect to Kafka using API KEY. Here is the link for reference: Results output

I have tried following commands but it is like throwing stone in the dark:

k6 run --logformat=raw --out kafka=brokers=<broker-name>,topic=<topic-name>,format=json,api-key=<Api-Key> <file-name>.js
k6 run --logformat=raw --out kafka=brokers=<broker-name>,topic=<topic-name>,format=json,apikey=<Api-Key> <file-name>.js
k6 run --logformat=raw --out kafka=brokers=<broker-name>,topic=<topic-name>,format=json,apiKey=<Api-Key> <file-name>.js

This is the error I am seeing when I run the above statements:

kafka: client has run out of available brokers to talk to (Is your cluster reachable?)

Can someone point me in the right direction to connect to Kafka using some form of authentication during K6 run?

Hi @adi_b09,

I am a k6 developer, but not a kafka user :frowning: . So I will need some more help from you.

  1. Can you run with -v and copy paste a little bit more of the output so we can see if this happens early on in the connection to kafka or later on when we try to write data to it
  2. Can you check with another tool that the kafka server is reachable at all as if it’s in docker there are apparently some problems.
  3. I went through the kafka documentation and googled around but can’t find any mention of an API KEY that is used for … protection. The only mention of api key in the documentation is about a numeric value that identifies the type of the request which doesn’t seem to be what you want.

Hopefully with those questions answered I will be able to help you :slight_smile: