Skip to content

Commit a9209e4

Browse files
authored
chore: Rename AsyncSubscriber to AsyncListener (#127)
Follows the naming of spring (listeners and publisher) Intention is to avoid confusion with the reversed naming in asyncApi, where - AsyncApi Publisher = Spring Listener - AsyncApi Subscriber = Spring Publisher
1 parent a8169f0 commit a9209e4

File tree

13 files changed

+40
-32
lines changed

13 files changed

+40
-32
lines changed

springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/ChannelPriority.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package io.github.stavshamir.springwolf.asyncapi.scanners.channels;
22

33
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.annotation.AsyncPublisher;
4-
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.annotation.AsyncSubscriber;
4+
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.annotation.AsyncListener;
55
import io.github.stavshamir.springwolf.configuration.AsyncApiDocket;
66

77
public class ChannelPriority {
@@ -15,7 +15,7 @@ public class ChannelPriority {
1515
/**
1616
* Definition via custom annotations
1717
* <p>
18-
* Example: {@link AsyncPublisher}, {@link AsyncSubscriber}
18+
* Example: {@link AsyncPublisher}, {@link AsyncListener}
1919
*/
2020
public static final int ASYNC_ANNOTATION = 2;
2121

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
import java.lang.annotation.Target;
99

1010
/**
11-
* {@code @AsyncSubscriber} is a method-level annotation to document springwolf listeners.
11+
* {@code @AsyncListener} is a method-level annotation to document springwolf listeners.
12+
* Listeners in this context are methods that receive and process incoming data from a message broker.
1213
* To document producers, use {@link AsyncPublisher}.
1314
* <p>
1415
* The fields channel, description, payload and headers are part of {@link AsyncOperation}
@@ -19,7 +20,7 @@
1920
* Add an operation binding with one of the protocol specific operation binding annotation ({@code AmqpAsyncOperationBinding}, {@code KafkaAsyncOperationBinding}) on the same method.
2021
* <pre class="code">
2122
* &#064;KafkaListener
22-
* &#064;AsyncSubscriber(operation = &#064;AsyncOperation(
23+
* &#064;AsyncListener(operation = &#064;AsyncOperation(
2324
* channelName = "topic-name",
2425
* ...
2526
* ))
@@ -29,7 +30,7 @@
2930
*/
3031
@Retention(RetentionPolicy.RUNTIME)
3132
@Target(value = {ElementType.METHOD})
32-
public @interface AsyncSubscriber {
33+
public @interface AsyncListener {
3334
/**
3435
* Mapped to {@link OperationData}
3536
*/
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
@RequiredArgsConstructor
2626
@Component
2727
@Order(value = ChannelPriority.ASYNC_ANNOTATION)
28-
public class AsyncSubscriberAnnotationScanner extends AbstractOperationDataScanner implements EmbeddedValueResolverAware {
28+
public class AsyncListenerAnnotationScanner extends AbstractOperationDataScanner implements EmbeddedValueResolverAware {
2929
private StringValueResolver resolver;
3030
private final ComponentClassScanner componentClassScanner;
3131
private final SchemasService schemasService;
@@ -52,7 +52,7 @@ protected List<OperationData> getOperationData() {
5252
}
5353

5454
private Set<Method> getAnnotatedMethods(Class<?> type) {
55-
Class<AsyncSubscriber> annotationClass = AsyncSubscriber.class;
55+
Class<AsyncListener> annotationClass = AsyncListener.class;
5656
log.debug("Scanning class \"{}\" for @\"{}\" annotated methods", type.getName(), annotationClass.getName());
5757

5858
return Arrays.stream(type.getDeclaredMethods())
@@ -65,8 +65,8 @@ private OperationData mapMethodToOperationData(Method method) {
6565

6666
Map<String, OperationBinding> operationBindings = AsyncAnnotationScannerUtil.processBindingFromAnnotation(method, operationBindingProcessors);
6767

68-
Class<AsyncSubscriber> annotationClass = AsyncSubscriber.class;
69-
AsyncSubscriber annotation = Optional.of(method.getAnnotation(annotationClass))
68+
Class<AsyncListener> annotationClass = AsyncListener.class;
69+
AsyncListener annotation = Optional.of(method.getAnnotation(annotationClass))
7070
.orElseThrow(() -> new IllegalArgumentException("Method must be annotated with " + annotationClass.getName()));
7171

7272
AsyncOperation op = annotation.operation();

springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/annotation/AsyncPublisher.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99

1010
/**
1111
* {@code @AsyncPublisher} is a method-level annotation to document springwolf publishers.
12-
* To document listeners, use {@link AsyncSubscriber}.
12+
* Publishers in this context are methods that send a message to a message broker.
13+
* To document listeners, use {@link AsyncListener}.
1314
* <p>
1415
* The fields channel, description, payload and headers are part of {@link AsyncOperation}
1516
* and behaves identical to {@link io.github.stavshamir.springwolf.asyncapi.types.ProducerData}.

springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/annotation/OperationBindingProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
public interface OperationBindingProcessor {
99

1010
/**
11-
* Process the methods annotated with {@link AsyncPublisher} and {@link AsyncSubscriber}
11+
* Process the methods annotated with {@link AsyncPublisher} and {@link AsyncListener}
1212
* for protocol specific operationBinding annotations, method parameters, etc
1313
*
1414
* @param method The method being annotated
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@
2929
import static org.mockito.Mockito.when;
3030

3131
@RunWith(SpringRunner.class)
32-
@ContextConfiguration(classes = {AsyncSubscriberAnnotationScanner.class, DefaultSchemasService.class, TestOperationBindingProcessor.class})
32+
@ContextConfiguration(classes = {AsyncListenerAnnotationScanner.class, DefaultSchemasService.class, TestOperationBindingProcessor.class})
3333
@TestPropertySource(properties = {"test.property.test-channel=test-channel", "test.property.description=description"})
34-
public class AsyncSubscriberAnnotationScannerTest {
34+
public class AsyncListenerAnnotationScannerTest {
3535

3636
@Autowired
37-
private AsyncSubscriberAnnotationScanner channelScanner;
37+
private AsyncListenerAnnotationScanner channelScanner;
3838

3939
@MockBean
4040
private ComponentClassScanner componentClassScanner;
@@ -46,7 +46,7 @@ private void setClassToScan(Class<?> classToScan) {
4646

4747
@Test
4848
public void scan_componentHasNoListenerMethods() {
49-
setClassToScan(ClassWithoutSubscriberAnnotation.class);
49+
setClassToScan(ClassWithoutListenerAnnotation.class);
5050

5151
Map<String, ChannelItem> channels = channelScanner.scan();
5252

@@ -56,7 +56,7 @@ public void scan_componentHasNoListenerMethods() {
5656

5757
@Test
5858
public void scan_componentHasListenerMethod() {
59-
// Given a class with methods annotated with AsyncSubscriber, where only the channel-name is set
59+
// Given a class with methods annotated with AsyncListener, where only the channel-name is set
6060
setClassToScan(ClassWithListenerAnnotation.class);
6161

6262
// When scan is called
@@ -89,7 +89,7 @@ public void scan_componentHasListenerMethod() {
8989

9090
@Test
9191
public void scan_componentHasListenerMethodWithAllAttributes() {
92-
// Given a class with method annotated with AsyncSubscriber, where all attributes are set
92+
// Given a class with method annotated with AsyncListener, where all attributes are set
9393
setClassToScan(ClassWithListenerAnnotationWithAllAttributes.class);
9494

9595
// When scan is called
@@ -121,15 +121,15 @@ public void scan_componentHasListenerMethodWithAllAttributes() {
121121
}
122122

123123

124-
private static class ClassWithoutSubscriberAnnotation {
124+
private static class ClassWithoutListenerAnnotation {
125125

126126
private void methodWithoutAnnotation() {
127127
}
128128
}
129129

130130
private static class ClassWithListenerAnnotation {
131131

132-
@AsyncSubscriber(operation = @AsyncOperation(
132+
@AsyncListener(operation = @AsyncOperation(
133133
channelName = "test-channel"
134134
))
135135
private void methodWithAnnotation(SimpleFoo payload) {
@@ -142,7 +142,7 @@ private void methodWithoutAnnotation() {
142142

143143
private static class ClassWithListenerAnnotationWithAllAttributes {
144144

145-
@AsyncSubscriber(operation = @AsyncOperation(
145+
@AsyncListener(operation = @AsyncOperation(
146146
channelName = "${test.property.test-channel}",
147147
description = "${test.property.description}",
148148
headers = @AsyncOperation.Headers(

springwolf-examples/springwolf-amqp-example/src/main/java/io/github/stavshamir/springwolf/example/configuration/AsyncApiConfiguration.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import com.asyncapi.v2.model.info.Info;
55
import com.asyncapi.v2.model.info.License;
66
import com.asyncapi.v2.model.server.Server;
7+
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.annotation.AsyncListener;
8+
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.annotation.AsyncPublisher;
79
import io.github.stavshamir.springwolf.asyncapi.types.AmqpConsumerData;
810
import io.github.stavshamir.springwolf.asyncapi.types.AmqpProducerData;
911
import io.github.stavshamir.springwolf.configuration.AsyncApiDocket;
@@ -32,8 +34,8 @@ public AsyncApiConfiguration(
3234
* This bean is only required if full control on the {@link AsyncApiDocket} is needed
3335
* <p>
3436
* By default, Springwolf uses the {@see Info} provided in the application.properties
35-
* Consumers are detected when the @RabbitListener or @AsyncSubscriber annotation is used
36-
* Producers are detected when the springwolf @AsyncPublisher annotation is used
37+
* Consumers are detected when the @RabbitListener or {@link AsyncListener} annotation is used
38+
* Producers are detected when the springwolf {@link AsyncPublisher} annotation is used
3739
*/
3840
@Bean
3941
@ConditionalOnProperty(value = "customAsyncApiDocketBean", havingValue = "true", matchIfMissing = true)

springwolf-examples/springwolf-cloud-stream-example/src/main/java/io/github/stavshamir/springwolf/example/configuration/AsyncApiConfiguration.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import com.asyncapi.v2.model.info.Info;
55
import com.asyncapi.v2.model.info.License;
66
import com.asyncapi.v2.model.server.Server;
7+
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.annotation.AsyncListener;
8+
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.annotation.AsyncPublisher;
79
import io.github.stavshamir.springwolf.configuration.AsyncApiDocket;
810
import io.github.stavshamir.springwolf.configuration.EnableAsyncApi;
911
import org.springframework.beans.factory.annotation.Value;
@@ -25,8 +27,8 @@ public AsyncApiConfiguration(@Value("${spring.kafka.bootstrap-servers}") String
2527
* This bean is only required if full control on the {@link AsyncApiDocket} is needed
2628
* <p>
2729
* By default, Springwolf uses the {@see Info} provided in the application.properties
28-
* Consumers are detected when the @KafkaListener or @AsyncSubscriber annotation is used
29-
* Producers are detected when the springwolf @AsyncPublisher annotation is used
30+
* Consumers are detected when the @KafkaListener or {@link AsyncListener} annotation is used
31+
* Producers are detected when the springwolf {@link AsyncPublisher} annotation is used
3032
*/
3133
@Bean
3234
@ConditionalOnProperty(value = "customAsyncApiDocketBean", havingValue = "true", matchIfMissing = true)

springwolf-examples/springwolf-kafka-example/src/main/java/io/github/stavshamir/springwolf/example/configuration/AsyncApiConfiguration.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import com.asyncapi.v2.model.info.Info;
55
import com.asyncapi.v2.model.info.License;
66
import com.asyncapi.v2.model.server.Server;
7+
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.annotation.AsyncListener;
8+
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.annotation.AsyncPublisher;
79
import io.github.stavshamir.springwolf.asyncapi.types.KafkaConsumerData;
810
import io.github.stavshamir.springwolf.asyncapi.types.KafkaProducerData;
911
import io.github.stavshamir.springwolf.asyncapi.types.channel.operation.message.header.AsyncHeaders;
@@ -35,8 +37,8 @@ public AsyncApiConfiguration(@Value("${kafka.bootstrap.servers}") String bootstr
3537
* This bean is only required if full control on the {@link AsyncApiDocket} is needed
3638
* <p>
3739
* By default, Springwolf uses the {@see Info} provided in the application.properties
38-
* Consumers are detected when the @KafkaListener or @AsyncSubscriber annotation is used
39-
* Producers are detected when the springwolf @AsyncPublisher annotation is used
40+
* Consumers are detected when the @KafkaListener or {@link AsyncListener} annotation is used
41+
* Producers are detected when the springwolf {@link AsyncPublisher} annotation is used
4042
*/
4143
@Bean
4244
@ConditionalOnProperty(value = "customAsyncApiDocketBean", havingValue = "true", matchIfMissing = true)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package io.github.stavshamir.springwolf.example.consumers;
22

33
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.annotation.AsyncOperation;
4-
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.annotation.AsyncSubscriber;
4+
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.annotation.AsyncListener;
55
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.annotation.KafkaAsyncOperationBinding;
66
import io.github.stavshamir.springwolf.example.dtos.AnotherPayloadDto;
77
import io.github.stavshamir.springwolf.example.dtos.ExamplePayloadDto;
@@ -33,9 +33,9 @@ public void receiveAnotherPayload(AnotherPayloadDto payload) {
3333
}
3434

3535
@KafkaHandler
36-
@AsyncSubscriber(operation = @AsyncOperation(
36+
@AsyncListener(operation = @AsyncOperation(
3737
channelName = "multi-payload-topic",
38-
description = "Override description in the AsyncSubscriber annotation with servers at ${kafka.bootstrap.servers}",
38+
description = "Override description in the AsyncListener annotation with servers at ${kafka.bootstrap.servers}",
3939
headers = @AsyncOperation.Headers(
4040
schemaName = "SpringKafkaDefaultHeaders-MonetaryAmount",
4141
values = {

0 commit comments

Comments
 (0)