GH-2708: Make messaging annotations as repeatable

Fixes https://github.com/spring-projects/spring-integration/issues/2708

There are some requests to use the same service method for different input channels

* Make all the messaging annotations as `@Repeatable` with their
respective container annotations
* Modify `MessagingAnnotationPostProcessor` logic to deal with the mentioned repeatable
requirements
This commit is contained in:
Artem Bilan
2022-04-18 17:07:39 -04:00
committed by Gary Russell
parent f54d4b3d75
commit 97ab596841
24 changed files with 454 additions and 40 deletions

View File

@@ -298,6 +298,12 @@ public class MessagingAnnotationPostProcessorTests {
inputChannel.send(new GenericMessage<>("foo"));
Message<?> reply = outputChannel.receive(0);
assertThat(reply.getPayload()).isEqualTo("FOO");
MessageChannel inputChannel2 = context.getBean("inputChannel2", MessageChannel.class);
inputChannel2.send(new GenericMessage<>("test2"));
reply = outputChannel.receive(0);
assertThat(reply.getPayload()).isEqualTo("TEST2");
context.close();
}
@@ -386,6 +392,7 @@ public class MessagingAnnotationPostProcessorTests {
public static class TransformerAnnotationTestBean {
@Transformer(inputChannel = "inputChannel", outputChannel = "outputChannel")
@Transformer(inputChannel = "inputChannel2", outputChannel = "outputChannel")
public String transformBefore(String input) {
return input.toUpperCase();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2021 the original author or authors.
* Copyright 2014-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -385,9 +385,9 @@ public class MessagingAnnotationsWithBeanAnnotationTests {
@Bean
@ServiceActivator(inputChannel = "skippedChannel")
@Splitter(inputChannel = "skippedChannel2")
@ServiceActivator(inputChannel = "skippedChannel2")
@Router(inputChannel = "skippedChannel3")
@Transformer(inputChannel = "skippedChannel4")
@Filter(inputChannel = "skippedChannel4")
@Filter(inputChannel = "skippedChannel5")
@Profile("foo")
public MessageHandler skippedMessageHandler() {
@@ -396,6 +396,7 @@ public class MessagingAnnotationsWithBeanAnnotationTests {
}
@Bean
@BridgeFrom("skippedChannel5")
@BridgeFrom("skippedChannel6")
@Profile("foo")
public MessageChannel skippedChannel1() {

View File

@@ -250,6 +250,9 @@ public class EnableIntegrationTests {
@Autowired
private PollableChannel messageChannel;
@Autowired
private PollableChannel messageChannel2;
@Autowired
private PollableChannel fooChannel;
@@ -432,6 +435,12 @@ public class EnableIntegrationTests {
assertThat(message.getHeaders().containsKey("foo")).isTrue();
assertThat(message.getHeaders().get("foo")).isEqualTo("FOO");
message = this.messageChannel2.receive(10_000);
assertThat(message).isNotNull();
assertThat(message.getPayload()).isEqualTo("bar");
assertThat(message.getHeaders().containsKey("foo")).isTrue();
assertThat(message.getHeaders().get("foo")).isEqualTo("FOO");
MessagingTemplate messagingTemplate = new MessagingTemplate(this.controlBusChannel);
assertThat(messagingTemplate.convertSendAndReceive("@pausable.isRunning()", Boolean.class)).isEqualTo(false);
this.controlBusChannel.send(new GenericMessage<>("@pausable.start()"));
@@ -1162,6 +1171,11 @@ public class EnableIntegrationTests {
return new QueueChannel();
}
@Bean
public PollableChannel messageChannel2() {
return new QueueChannel();
}
@Bean
public QueueChannel numberChannel() {
QueueChannel channel = new QueueChannel();
@@ -1354,6 +1368,7 @@ public class EnableIntegrationTests {
@InboundChannelAdapter(value = "messageChannel", poller = @Poller(fixedDelay = "${poller.interval}",
maxMessagesPerPoll = "1"))
@InboundChannelAdapter(value = "messageChannel2", poller = @Poller(fixedDelay = "100"))
public Message<?> message() {
return MessageBuilder.withPayload("bar").setHeader("foo", "FOO").build();
}