GithubHelp home page GithubHelp logo

pandaente / springwolf-kafka Goto Github PK

View Code? Open in Web Editor NEW

This project forked from springwolf/springwolf-kafka

0.0 0.0 0.0 80 KB

Automated documentation for Spring Boot application with Kafka consumers

License: Apache License 2.0

Java 93.39% Kotlin 6.61%

springwolf-kafka's Introduction

version springwolf-core License

Springwolf Kafka Plugin

Automated documentation for Spring Boot application with Kafka consumers

Table Of Contents

About

This plugin generates an AsyncAPI document from @KafkaListener methods. For more information, check out springwolf-core.

Usage

Add the following dependencies and configuration class to enable this plugin.

Dependencies

repositories {
    jcenter()
}
dependencies {
    // Provides the documentation API    
    implementation 'io.github.stavshamir:springwolf-kafka:0.1.0'
    
    // Provides the UI - optional (recommended)
    runtimeOnly 'io.github.stavshamir:springwolf-ui:0.0.2'
}

Configuration class

Add a configuration class and provide a KafkaProtocolConfiguration bean and a AsyncApiDocket bean:

@Configuration
@EnableAsyncApi
public class AsyncApiConfiguration {

    private final static String BOOTSTRAP_SERVERS = "localhost:9092"; // Change to your actual bootstrap server

    @Bean
    public KafkaProtocolConfiguration kafkaProtocolConfiguration() {
        return KafkaProtocolConfiguration.builder()
                .basePackage("io.github.stavshamir.springwolf.example.consumers") // Change to your actual base package of listeners
                .producerConfiguration(buildProducerConfiguration(BOOTSTRAP_SERVERS))
                .build();
    }

    @Bean
    public AsyncApiDocket asyncApiDocket() {
        Info info = Info.builder()
                .version("1.0.0")
                .title("Springwolf example project")
                .build();

        return AsyncApiDocket.builder()
                .info(info)
                .server("kafka", Server.kafka().url(BOOTSTRAP_SERVERS).build())
                .build();
    }

    private Map<String, Object> buildProducerConfiguration(String bootstrapServers) {
        return ImmutableMap.<String, Object>builder()
                .put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers)
                .put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class)
                .put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, JsonSerializer.class)
                .put(JsonSerializer.ADD_TYPE_INFO_HEADERS, false)
                .build();
    }

}

The basePackage field must be set with the name of the package containing the classes to be scanned for @KafkaListener annotated methods.

Verify

If you have included the UI dependency, access it with the following url: localhost:8080/asyncapi-ui.html. If not, try the following endpoint: localhost:8080/asyncapi/docs.

Example Project

See springwolf-kafka-example.

springwolf-kafka's People

Contributors

stavshamir avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.