69

I have just tried creating a Kafka topic "user:created" and saw this error in Kafka logs: Invalid character ':' in value part of property. I googled and found that in a mailing list people are talking about deprecating . and _ symbols too.

Which symbols can't be used in Apache Kafka topic names?

1 Answer 1

100

According to source code for kafka 10

val legalChars = "[a-zA-Z0-9\\._\\-]"
private val maxNameLength = 255
private val rgx = new Regex(legalChars + "+")

So, max length is 255 symbols and letters, . (dot), _ (underscore), - (minus) can use used

In the Kafka 0.10 the maxNameLength was changed from 255 to 249. See commit

Also topics with a period . or underscore _ could collide in internal data structures, so you are advised to use either but not both (source).

4
  • 3
    The '.' and '' are allowed but should be considered as the same character. "WARNING: Due to limitations in metric names, topics with a period ('.') or underscore ('') could collide. To avoid issues it is best to use either, but not both."
    – phreed
    Commented Apr 11, 2017 at 16:35
  • 6
    From the commit the reason the topic name is limited to 249: "Each sharded partition log is placed into its own folder under the Kafka log directory. The name of such folders consists of the topic name, appended by a dash (-) and the partition id. Since a typical folder name can not be over 255 characters long, there will be a limitation on the length of topic names. We assume the number of partitions will not ever be above 100000. Therefore, topic names cannot be longer than 249 characters. This leaves just enough room in the folder name for a dash and a potentially 5 digit long partition id"
    – deFreitas
    Commented Feb 13, 2018 at 0:46
  • 3
    Hi @phreed, is there a way to get rid of this "annoying" warning? Please do not tell me not to use underscore, as i want to use them for "readability" purpose ;-) Commented Nov 28, 2019 at 3:38
  • 3
    As of June 16, 2022, all the above restrictions appear to be the same. See the moved source code: github.com/apache/kafka/blob/… Commented Jul 5, 2022 at 3:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.