Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kafka documentation #356

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,15 @@
},
{
"type": "java",
"name": "Spring Boot-TestBootKafkaSampleApplication<spring-boot-kafka-sample>",
"request": "launch",
"cwd": "${workspaceFolder}",
"mainClass": "com.example.springbootkafkasample.TestBootKafkaSampleApplication",
"projectName": "spring-boot-kafka-sample",
"args": "",
"envFile": "${workspaceFolder}/.env"
},
{
"name": "Spring Boot-Application<spring-modulith-outbox-pattern>",
"request": "launch",
"cwd": "${workspaceFolder}",
Expand Down
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"java.jdt.ls.vmargs": "-XX:+UseParallelGC -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -Dsun.zip.disableMemoryMapping=true -Xmx2G -Xms100m -javaagent:\"/workspace/.vscode-remote/extensions/gabrielbb.vscode-lombok-1.0.1/server/lombok.jar\"",
"java.configuration.updateBuildConfiguration": "automatic",
"java.compile.nullAnalysis.mode": "automatic"
"java.compile.nullAnalysis.mode": "automatic",
"java.debug.settings.onBuildFailureProceed": true
}
4 changes: 4 additions & 0 deletions kafka-sample/spring-boot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@
This sample demonstrates sending message to topic (test_1), after listening to it will send the same message to (test_2).

test_2 topic is configured for validation and if it fails then it will be retried for 3 times and moved to deadletter queue using non blocking way


### URLS
* KafkaUI : http://localhost:8080/springwolf/asyncapi-ui.html
12 changes: 12 additions & 0 deletions kafka-sample/spring-boot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>${springdoc-openapi.version}</version>
</dependency>
<!-- Provides the documentation API -->
<dependency>
<groupId>io.github.springwolf</groupId>
<artifactId>springwolf-kafka</artifactId>
<version>0.13.0</version>
</dependency>
<!-- Provides the UI - optional (recommended) -->
<dependency>
<groupId>io.github.springwolf</groupId>
<artifactId>springwolf-ui</artifactId>
<version>0.13.0</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package com.example.springbootkafkasample.service.sender;

import static org.springframework.kafka.support.mapping.AbstractJavaTypeMapper.DEFAULT_CLASSID_FIELD_NAME;

import com.example.springbootkafkasample.dto.MessageDTO;
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.annotation.AsyncOperation;
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.annotation.AsyncPublisher;
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.annotation.KafkaAsyncOperationBinding;
import java.util.UUID;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -18,6 +23,21 @@ public Sender(KafkaTemplate<UUID, MessageDTO> template) {
this.template = template;
}

@AsyncPublisher(
operation =
@AsyncOperation(
channelName = "test1",
description = "MessageDTO payload",
headers =
@AsyncOperation.Headers(
schemaName = "SpringKafkaDefaultHeaders",
values = {
@AsyncOperation.Headers.Header(
name = DEFAULT_CLASSID_FIELD_NAME,
description = "Spring Type Id Header",
value = "com.example.springbootkafkasample.dto.MessageDTO"),
})))
@KafkaAsyncOperationBinding
public void send(MessageDTO messageDTO) {
this.template.send(messageDTO.topic(), UUID.randomUUID(), messageDTO).whenComplete((result, ex) -> {
if (ex == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
server.port=8080
spring.application.name=boot-kafka-sample

spring.kafka.consumer.group-id=foo
spring.kafka.consumer.auto-offset-reset=latest
Expand All @@ -8,4 +10,20 @@ spring.kafka.consumer.properties.spring.json.trusted.packages=com.example.spring

spring.kafka.producer.key-serializer=org.apache.kafka.common.serialization.UUIDSerializer
spring.kafka.producer.value-serializer=org.springframework.kafka.support.serializer.JsonSerializer
spring.threads.virtual.enabled=true

spring.threads.virtual.enabled=true


##89 springwolf
springwolf.docket.base-package=com.example.springbootkafkasample
springwolf.docket.id=urn:com.example:boot-sample-kafka
springwolf.docket.default-content-type=application/json

springwolf.docket.info.title=${spring.application.name}
springwolf.docket.info.version=1.0.0
springwolf.docket.info.license.name=Apache License 2.0

springwolf.docket.servers.kafka.protocol=kafka
springwolf.docket.servers.kafka.url=${spring.kafka.bootstrap-servers:localhost:9092}

springwolf.plugin.kafka.publishing.enabled=true
Loading