Skip to content

Commit 4568e3a

Browse files
committed
docs: Document @AsyncPublisher
1 parent 9d8044d commit 4568e3a

File tree

2 files changed

+96
-23
lines changed

2 files changed

+96
-23
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
sidebar_position: 5
33
---
44

5-
# Manually Documenting Consumers
5+
# Documenting Consumers
66

7-
Sometimes projects are configured in a way that makes Springwolf unable to automatically locate consumers, producers are defined imperatively (They don't have the `@KafkaListener` or `@RabbitListener` annotations on the consuming methods).
7+
Sometimes projects are configured in a way that makes Springwolf unable to automatically locate consumers (They don't have the `@KafkaListener`, `@RabbitListener`, `@AsyncSubscriber` annotations on the consuming methods).
88

99
Because there is still immense value in documenting the consumers, Springwolf provides a way to explicitly add them to the generated document, by declaring them in the `AsyncApiDocket` using the `ConsumerData` object.
1010

docs/documenting-producers.md

Lines changed: 94 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,79 @@ sidebar_position: 5
66

77
Unlike consumers which are defined declaratively with an annotation, producers are defined imperatively, and there is no implementation uniform enough so that metadata can be picked up automatically.
88

9-
Because producers are also an important part of Async APIs, Springwolf provides a way to explicitly add them to the generated document, by declaring them in the `AsyncApiDocket` using the `ProducerData` object.
9+
Because producers are also an important part of Async APIs, Springwolf provides a way to explicitly add them to the generated document.
1010

11-
## `ProducerData`
11+
To document them, either:
12+
- add the `@AsyncPublisher` annotation or
13+
- declare the `ProducerData` object as part of the `AsyncApiDocket`
14+
15+
## Option 1: `@AsyncPublisher`
16+
17+
The `@AsyncPublisher` annotation is added to the method of the publisher and extracts the payload from its arguments.
18+
Additional fields can be documented.
19+
20+
The protocol binding is configured via `@AmqpAsyncOperationBinding` or `@KafkaAsyncOperationBinding`, which has to be on the same method.
21+
22+
Below is an example to demonstrate the annotation:
23+
```java
24+
@AsyncPublisher(operation = @AsyncOperation(
25+
channelName = "example-producer-topic",
26+
description = "Optional. Customer uploaded an example payload",
27+
headers = @AsyncOperation.Headers(
28+
schemaName = "SpringKafkaDefaultHeaders",
29+
values = {
30+
@AsyncOperation.Headers.Header(
31+
name = DEFAULT_CLASSID_FIELD_NAME,
32+
description = "Spring Type Id Header",
33+
value = "io.github.stavshamir.springwolf.example.dtos.ExamplePayloadDto"
34+
),
35+
}
36+
)
37+
))
38+
@KafkaAsyncOperationBinding
39+
public void sendMessage(ExamplePayloadDto msg) {
40+
// send
41+
}
42+
```
43+
44+
### Channel Name
45+
46+
The channel name (or topic name in case of Kafka) - this is the name that will be used to publish messages to by the UI.
47+
48+
### Description
49+
50+
Optional. The description allows for human-friendly text to verbosely explain the _message_, like specific domain, what the topic is used for and which data it contains.
51+
52+
### Payload Type
53+
54+
The class object of the payload that will be published to this channel.
55+
If not specified, it is extracted from the method arguments.
56+
57+
### Header
58+
59+
Optional. The headers describing the metadata of the payload.
60+
61+
### `@AmqpAsyncOperationBinding`
62+
63+
Associate this operation with amqp, see [operation-binding] for details.
64+
65+
```java
66+
@AmqpAsyncOperationBinding(cc = "example-topic-routing-key")
67+
```
68+
69+
### `@KafkaAsyncOperationBinding`
70+
71+
Associate this operation with kafka, see [operation-binding] for details.
72+
73+
```java
74+
@KafkaAsyncOperationBinding(
75+
bindingVersion = "1",
76+
clientId = "foo-clientId",
77+
groupId = "#{'foo-groupId'}"
78+
)
79+
```
80+
81+
## Option 2: `ProducerData`
1282

1383
:::tip
1484
Use specific ProducerData types `AmqpProducerData` & `KafkaProducerData` for protocol specific attributes
@@ -49,7 +119,7 @@ Optional. The description allows for human-friendly text to verbosely explain th
49119

50120
### Binding
51121

52-
This property is used to discriminate the producer's protocol and provide protocol-specific properties (see [Operation Binding Object](https://www.asyncapi.com/docs/specifications/v2.0.0#operationBindingsObject)).
122+
This property is used to discriminate the producer's protocol and provide protocol-specific properties (see [operation-binding])).
53123

54124
### Payload Type
55125

@@ -62,7 +132,7 @@ By default, `AsyncHeaders.NOT_DOCUMENTED` is used to indicate that no explicit h
62132
Use `AsyncHeaders` to add your custom headers, use `AsyncHeaders.NOT_USED` if you do not use headers and `AsyncHeadersForCloudEventsBuilder` if your events follow the CloudEvent specification.
63133

64134

65-
## `AmqpProducerData`
135+
### `AmqpProducerData`
66136

67137
The above Kafka `ProducerData` equivalent in `AmqpProducerData`:
68138
```java
@@ -75,6 +145,21 @@ The above Kafka `ProducerData` equivalent in `AmqpProducerData`:
75145
.build();
76146
```
77147

148+
149+
150+
### `KafkaProducerData`
151+
152+
The above Kafka `ProducerData` simplifies to the following `KafkaProducerData`:
153+
```java
154+
KafkaProducerData exampleProducerData = KafkaProducerData.kafkaProducerDataBuilder()
155+
.topicName("example-producer-topic")
156+
.description("Optional. Customer uploaded an example payload")
157+
.payloadType(ExamplePayloadDto.class)
158+
.headers(AsyncHeaders.NOT_USED)
159+
.build();
160+
```
161+
162+
## AMQP Parameters
78163
### Queue Name (Channel Name)
79164

80165
The queue name that will be used to publish messages to by the UI.
@@ -95,22 +180,7 @@ The routing key used when publishing a message.
95180

96181
The class object of the payload that will be published to this channel.
97182

98-
### Example
99-
100-
See a full example [here](https://github.com/springwolf/springwolf-core/blob/master/springwolf-examples/springwolf-amqp-example/src/main/java/io/github/stavshamir/springwolf/example/configuration/AsyncApiConfiguration.java).
101-
102-
103-
## `KafkaProducerData`
104-
105-
The above Kafka `ProducerData` simplifies to the following `KafkaProducerData`:
106-
```java
107-
KafkaProducerData exampleProducerData = KafkaProducerData.kafkaProducerDataBuilder()
108-
.topicName("example-producer-topic")
109-
.description("Optional. Customer uploaded an example payload")
110-
.payloadType(ExamplePayloadDto.class)
111-
.headers(AsyncHeaders.NOT_USED)
112-
.build();
113-
```
183+
## Kafka Parameters
114184

115185
### Topic Name (Channel Name)
116186

@@ -132,4 +202,7 @@ The Springwolf Kafka plugin comes with a special `AsyncHeadersForSpringKafkaBuil
132202

133203
### Example
134204

135-
See a full example [here](https://github.com/springwolf/springwolf-core/blob/master/springwolf-examples/springwolf-kafka-example/src/main/java/io/github/stavshamir/springwolf/example/configuration/AsyncApiConfiguration.java).
205+
- [AMQP Example](https://github.com/springwolf/springwolf-core/blob/master/springwolf-examples/springwolf-amqp-example/src/main/java/io/github/stavshamir/springwolf/example/configuration/AsyncApiConfiguration.java)
206+
- [Kafka Example](https://github.com/springwolf/springwolf-core/blob/master/springwolf-examples/springwolf-kafka-example/src/main/java/io/github/stavshamir/springwolf/example/configuration/AsyncApiConfiguration.java)
207+
208+
[operation-binding]: https://www.asyncapi.com/docs/reference/specification/v2.0.0#operationBindingsObject

0 commit comments

Comments
 (0)