Skip to content

Commit a724f18

Browse files
committed
Adapt springwolf-kafka-example to the new annotation structure, to contain an example for the key and to the change that a kafka message binding is always present
1 parent 23098d1 commit a724f18

File tree

3 files changed

+39
-9
lines changed

3 files changed

+39
-9
lines changed

springwolf-examples/springwolf-kafka-example/src/main/java/io/github/stavshamir/springwolf/example/consumers/ExampleClassLevelKafkaListener.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
import javax.money.MonetaryAmount;
1515

16-
import static io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.annotation.KafkaAsyncOperationBinding.KafkaAsyncMessageBinding.KafkaKeyTypes.STRING_KEY;
1716
import static org.springframework.kafka.support.mapping.AbstractJavaTypeMapper.DEFAULT_CLASSID_FIELD_NAME;
1817

1918

@@ -52,9 +51,11 @@ public void receiveAnotherPayload(AnotherPayloadDto payload) {
5251
clientId = "foo-clientId",
5352
groupId = "#{'foo-groupId'}",
5453
messageBinding = @KafkaAsyncMessageBinding(
55-
keyType = STRING_KEY,
56-
bindingVersion = "1",
57-
description = "Kafka Consumer Message Key"
54+
key = @KafkaAsyncOperationBinding.KafkaAsyncKey(
55+
description = "Kafka Consumer Message Key",
56+
example = "example-key"
57+
),
58+
bindingVersion = "1"
5859
)
5960
)
6061
public void receiveMonetaryAmount(MonetaryAmount payload) {

springwolf-examples/springwolf-kafka-example/src/main/java/io/github/stavshamir/springwolf/example/producers/ExampleProducer.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.annotation.AsyncOperation;
44
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.annotation.AsyncPublisher;
55
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.annotation.KafkaAsyncOperationBinding;
6+
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.annotation.KafkaAsyncOperationBinding.KafkaAsyncKey;
67
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.annotation.KafkaAsyncOperationBinding.KafkaAsyncMessageBinding;
78
import io.github.stavshamir.springwolf.example.dtos.ExamplePayloadDto;
89
import org.springframework.beans.factory.annotation.Autowired;
910
import org.springframework.kafka.core.KafkaTemplate;
1011
import org.springframework.stereotype.Component;
1112

12-
import static io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.annotation.KafkaAsyncOperationBinding.KafkaAsyncMessageBinding.KafkaKeyTypes.STRING_KEY;
1313
import static io.github.stavshamir.springwolf.example.configuration.KafkaConfiguration.PRODUCER_TOPIC;
1414
import static org.springframework.kafka.support.mapping.AbstractJavaTypeMapper.DEFAULT_CLASSID_FIELD_NAME;
1515

@@ -42,9 +42,11 @@ public class ExampleProducer {
4242
bindingVersion = "1",
4343
clientId = "foo-clientId",
4444
messageBinding = @KafkaAsyncMessageBinding(
45-
keyType = STRING_KEY,
46-
bindingVersion = "1",
47-
description = "Kafka Producer Message Key"
45+
key = @KafkaAsyncKey(
46+
description = "Kafka Producer Message Key",
47+
example = "example-key"
48+
),
49+
bindingVersion = "1"
4850
)
4951
)
5052
public void sendMessage(ExamplePayloadDto msg) {

springwolf-examples/springwolf-kafka-example/src/test/resources/asyncapi.json

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@
6363
},
6464
"headers" : {
6565
"$ref" : "#/components/schemas/HeadersNotDocumented"
66+
},
67+
"bindings" : {
68+
"kafka" : { }
6669
}
6770
}
6871
},
@@ -87,6 +90,9 @@
8790
},
8891
"headers" : {
8992
"$ref" : "#/components/schemas/CloudEventHeadersForAnotherPayloadDtoEndpoint"
93+
},
94+
"bindings" : {
95+
"kafka" : { }
9096
}
9197
}, {
9298
"name" : "io.github.stavshamir.springwolf.example.dtos.ExamplePayloadDto",
@@ -97,6 +103,17 @@
97103
},
98104
"headers" : {
99105
"$ref" : "#/components/schemas/SpringKafkaDefaultHeaders"
106+
},
107+
"bindings" : {
108+
"kafka" : {
109+
"key" : {
110+
"type" : "string",
111+
"description" : "Kafka Producer Message Key",
112+
"example" : "example-key",
113+
"exampleSetFlag" : true,
114+
"types" : [ "string" ]
115+
}
116+
}
100117
}
101118
} ]
102119
}
@@ -120,6 +137,9 @@
120137
},
121138
"headers" : {
122139
"$ref" : "#/components/schemas/HeadersNotDocumented"
140+
},
141+
"bindings" : {
142+
"kafka" : { }
123143
}
124144
}
125145
},
@@ -148,6 +168,9 @@
148168
},
149169
"headers" : {
150170
"$ref" : "#/components/schemas/SpringKafkaDefaultHeaders-AnotherPayloadDto"
171+
},
172+
"bindings" : {
173+
"kafka" : { }
151174
}
152175
}, {
153176
"name" : "io.github.stavshamir.springwolf.example.dtos.ExamplePayloadDto",
@@ -157,6 +180,9 @@
157180
},
158181
"headers" : {
159182
"$ref" : "#/components/schemas/SpringKafkaDefaultHeaders-ExamplePayloadDto"
183+
},
184+
"bindings" : {
185+
"kafka" : { }
160186
}
161187
}, {
162188
"name" : "javax.money.MonetaryAmount",
@@ -173,7 +199,8 @@
173199
"key" : {
174200
"type" : "string",
175201
"description" : "Kafka Consumer Message Key",
176-
"exampleSetFlag" : false,
202+
"example" : "example-key",
203+
"exampleSetFlag" : true,
177204
"types" : [ "string" ]
178205
},
179206
"bindingVersion" : "1"

0 commit comments

Comments
 (0)