Joseph Downing Joseph Downing - 1 year ago 78
Groovy Question

Why am I getting a ConfigException 'Expected a comma separated list' error when creating a KafkaConsumer

I am trying to create a

with the following

Properties props = new Properties()
props.put('bootstrap.servers', "$SERVER_ADDRESS:$port")
return new KafkaConsumer<String, String>(props)

When I execute it, I am getting the following error:

org.apache.kafka.common.config.ConfigException: Invalid value
localhost:9092 for configuration bootstrap.servers: Expected a comma
separated list.

My code essentially matches the example creation of a Consumer from here

Why is my version not working?

Answer Source

In this case, the props object is expecting its values to be of type Object, and not only of type String. Therefore, when "$SERVER_ADDRESS:$port" is added as a property, it isn't coerced into a String and is stored as a GStringImpl.

The type checking done before creating a KafkaConsumer knows how to handle a String property value but not a GStringImpl and throws an error.

Changing the line to this works:

props.put('bootstrap.servers', "$SERVER_ADDRESS:$port".toString())