Spring Kafka Documentation

This tool is created for auto generated kafka documentation with spring projects. YAML/JSON document is built in Async API format.

How to use

  • Implement these to build.gradle.kts.
maven { url = uri("https://jitpack.io") }
  • Add asyncapi configuration file

class AsyncApiConfiguration {

    fun asyncApiDocket(): AsyncApiDocket {

        val info = Info.builder()
            .title("ZubizuLF Customer API")

        val kafkaServer = Server.builder()

        return AsyncApiDocket.builder()
            .server("kafka", kafkaServer)

    private companion object {
        const val BOOTSTRAP_SERVERS = ""
        const val KAFKA_CONSUMER_BASE_PACKAGE = "com.dteknoloji.*.consumer"
        const val KAFKA_PRODUCER_BASE_PACKAGE = "com.dteknoloji.*.producer"

Consumers are included in the consumer package, and producer in the producer package. A project does not have to be both a consumer and a producer. Even if it’s one of the two, this tool works properly.

In order for this tool to work properly, consumers and producers must be as follows.

Consumer example:

class CustomerCreatedEventConsumer {

    @KafkaListener(topicPattern = "\${kafka.topics.customerCreated}")
    fun receive(@Payload payload: CustomerCreatedEvent) {
        // TODO

Producer example:

class CustomerCreatedEventProducer {

    fun send(@Payload payload: CustomerCreatedEvent) {
        // TODO

In the added configuration file, we specify which package the consumers and producers have. The tool detects the consumers and producers in the project by finding the classes that use the @Component annotation.

Normally, an annotation is not required for the methods or payloads of the producers. But, we use kafka’s @Payload annotation for payloads to create the producer document. In addition, we use the @AsyncApiProducer annotation created in the tool to understand which topic the events are thrown to.

We use the topicPattern parameter, which we want to pull the consumer topic names from the config files. There is a rule to get the last word here. There is a topicPattern parameter in the @AsyncApiProducer annotation, but whatever value is given to that parameter, that value is used as it is.


In this project, there are two endpoints.

  • GET /springkafkadoc/json
  • GET /springkafkadoc/yaml

By using these endpoints, you can get AsyncAPI documents in JSON/YAML formats.



Async API

This tool is very inspired by the springwolf project, which is an open source tool. ❤️


View Github