This plugin generates an AsyncAPI document from @KafkaListener
methods.
For more information, check out springwolf-core.
Add the following dependencies and configuration class to enable this plugin.
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'
}
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.
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
.