Skip to content

Commit cd03684

Browse files
committed
Remove @MessagingGateway usage
The `@MessagingGateway` requires a classpath scanning which is not possible when we use these function artifacts as dependencies, where packages are fully different from what target project is built with
1 parent 73111d9 commit cd03684

File tree

5 files changed

+41
-23
lines changed

5 files changed

+41
-23
lines changed

consumer/spring-cassandra-consumer/src/main/java/org/springframework/cloud/fn/consumer/cassandra/CassandraConsumerConfiguration.java

+9-3
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@
4747
import org.springframework.data.cassandra.core.WriteResult;
4848
import org.springframework.data.cassandra.core.cql.WriteOptions;
4949
import org.springframework.integration.JavaUtils;
50-
import org.springframework.integration.annotation.MessagingGateway;
5150
import org.springframework.integration.cassandra.outbound.CassandraMessageHandler;
5251
import org.springframework.integration.dsl.IntegrationFlow;
52+
import org.springframework.integration.gateway.AnnotationGatewayProxyFactoryBean;
5353
import org.springframework.integration.support.json.Jackson2JsonObjectMapper;
5454
import org.springframework.integration.transformer.AbstractPayloadTransformer;
5555
import org.springframework.messaging.MessageHandler;
@@ -71,7 +71,7 @@ public class CassandraConsumerConfiguration {
7171
private CassandraConsumerProperties cassandraSinkProperties;
7272

7373
@Bean
74-
public Consumer<Object> cassandraConsumer(CassandraConsumerFunction cassandraConsumerFunction) {
74+
Consumer<Object> cassandraConsumer(CassandraConsumerFunction cassandraConsumerFunction) {
7575
return (payload) -> cassandraConsumerFunction.apply(payload).block();
7676
}
7777

@@ -121,6 +121,13 @@ public MessageHandler cassandraMessageHandler(ReactiveCassandraOperations cassan
121121
return cassandraMessageHandler;
122122
}
123123

124+
@Bean
125+
AnnotationGatewayProxyFactoryBean<CassandraConsumerFunction> cassandraConsumerFunction() {
126+
var gatewayProxyFactoryBean = new AnnotationGatewayProxyFactoryBean<>(CassandraConsumerFunction.class);
127+
gatewayProxyFactoryBean.setDefaultRequestChannelName("cassandraConsumerFlow.input");
128+
return gatewayProxyFactoryBean;
129+
}
130+
124131
private static boolean isUuid(String uuid) {
125132
if (uuid.length() == 36) {
126133
String[] parts = uuid.split("-");
@@ -198,7 +205,6 @@ protected boolean looksLikeISO8601(String dateStr) {
198205

199206
}
200207

201-
@MessagingGateway(name = "cassandraConsumerFunction", defaultRequestChannel = "cassandraConsumerFlow.input")
202208
interface CassandraConsumerFunction extends Function<Object, Mono<? extends WriteResult>> {
203209

204210
}

consumer/spring-elasticsearch-consumer/src/main/java/org/springframework/cloud/fn/consumer/elasticsearch/ElasticsearchConsumerConfiguration.java

+9-6
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@
4545
import org.springframework.context.annotation.Bean;
4646
import org.springframework.integration.aggregator.AbstractAggregatingMessageGroupProcessor;
4747
import org.springframework.integration.aggregator.MessageCountReleaseStrategy;
48-
import org.springframework.integration.annotation.MessagingGateway;
4948
import org.springframework.integration.config.AggregatorFactoryBean;
5049
import org.springframework.integration.dsl.IntegrationFlow;
5150
import org.springframework.integration.expression.ValueExpression;
51+
import org.springframework.integration.gateway.AnnotationGatewayProxyFactoryBean;
5252
import org.springframework.integration.store.MessageGroup;
5353
import org.springframework.integration.store.MessageGroupStore;
5454
import org.springframework.integration.store.SimpleMessageStore;
@@ -138,6 +138,14 @@ IntegrationFlow elasticsearchConsumerFlow(@Qualifier("aggregator") MessageHandle
138138
};
139139
}
140140

141+
@Bean
142+
@SuppressWarnings({ "unchecked", "rawtypes" })
143+
AnnotationGatewayProxyFactoryBean<Consumer<Message<?>>> elasticsearchConsumer() {
144+
var gatewayProxyFactoryBean = new AnnotationGatewayProxyFactoryBean<>(Consumer.class);
145+
gatewayProxyFactoryBean.setDefaultRequestChannelName("elasticsearchConsumerFlow.input");
146+
return (AnnotationGatewayProxyFactoryBean) gatewayProxyFactoryBean;
147+
}
148+
141149
@Bean
142150
public MessageHandler indexingHandler(ElasticsearchClient elasticsearchClient,
143151
ElasticsearchConsumerProperties consumerProperties) {
@@ -303,9 +311,4 @@ record MessageWrapper(Message<?> message) {
303311

304312
}
305313

306-
@MessagingGateway(name = "elasticsearchConsumer", defaultRequestChannel = "elasticsearchConsumerFlow.input")
307-
private interface MessageConsumer extends Consumer<Message<?>> {
308-
309-
}
310-
311314
}

consumer/spring-jdbc-consumer/src/main/java/org/springframework/cloud/fn/consumer/jdbc/JdbcConsumerConfiguration.java

+9-6
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@
4444
import org.springframework.expression.spel.standard.SpelExpressionParser;
4545
import org.springframework.integration.aggregator.DefaultAggregatingMessageGroupProcessor;
4646
import org.springframework.integration.aggregator.MessageCountReleaseStrategy;
47-
import org.springframework.integration.annotation.MessagingGateway;
4847
import org.springframework.integration.config.AggregatorFactoryBean;
4948
import org.springframework.integration.context.IntegrationContextUtils;
5049
import org.springframework.integration.dsl.IntegrationFlow;
5150
import org.springframework.integration.expression.ValueExpression;
51+
import org.springframework.integration.gateway.AnnotationGatewayProxyFactoryBean;
5252
import org.springframework.integration.jdbc.JdbcMessageHandler;
5353
import org.springframework.integration.jdbc.SqlParameterSourceFactory;
5454
import org.springframework.integration.store.MessageGroupStore;
@@ -131,6 +131,14 @@ IntegrationFlow jdbcConsumerFlow(@Qualifier("aggregator") MessageHandler aggrega
131131
};
132132
}
133133

134+
@Bean
135+
@SuppressWarnings({ "unchecked", "rawtypes" })
136+
AnnotationGatewayProxyFactoryBean<Consumer<Message<?>>> jdbcConsumer() {
137+
var gatewayProxyFactoryBean = new AnnotationGatewayProxyFactoryBean<>(Consumer.class);
138+
gatewayProxyFactoryBean.setDefaultRequestChannelName("jdbcConsumerFlow.input");
139+
return (AnnotationGatewayProxyFactoryBean) gatewayProxyFactoryBean;
140+
}
141+
134142
@Bean
135143
FactoryBean<MessageHandler> aggregator(MessageGroupStore messageGroupStore) {
136144
AggregatorFactoryBean aggregatorFactoryBean = new AggregatorFactoryBean();
@@ -232,11 +240,6 @@ public DataSourceInitializer nonBootDataSourceInitializer(DataSource dataSource,
232240
return dataSourceInitializer;
233241
}
234242

235-
@MessagingGateway(name = "jdbcConsumer", defaultRequestChannel = "jdbcConsumerFlow.input")
236-
public interface MessageConsumer extends Consumer<Message<?>> {
237-
238-
}
239-
240243
private record ParameterFactory(MultiValueMap<String, Expression> columnExpressions,
241244
EvaluationContext context) implements SqlParameterSourceFactory {
242245

consumer/spring-log-consumer/src/main/java/org/springframework/cloud/fn/consumer/log/LogConsumerConfiguration.java

+7-4
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
import org.springframework.boot.autoconfigure.AutoConfiguration;
2222
import org.springframework.boot.context.properties.EnableConfigurationProperties;
2323
import org.springframework.context.annotation.Bean;
24-
import org.springframework.integration.annotation.MessagingGateway;
2524
import org.springframework.integration.dsl.IntegrationFlow;
25+
import org.springframework.integration.gateway.AnnotationGatewayProxyFactoryBean;
2626
import org.springframework.messaging.Message;
2727

2828
/**
@@ -46,9 +46,12 @@ IntegrationFlow logConsumerFlow(LogConsumerProperties logSinkProperties) {
4646
.nullChannel();
4747
}
4848

49-
@MessagingGateway(name = "logConsumer", defaultRequestChannel = "logConsumerFlow.input")
50-
private interface MessageConsumer extends Consumer<Message<?>> {
51-
49+
@Bean
50+
@SuppressWarnings({ "unchecked", "rawtypes" })
51+
AnnotationGatewayProxyFactoryBean<Consumer<Message<?>>> logConsumer() {
52+
var gatewayProxyFactoryBean = new AnnotationGatewayProxyFactoryBean<>(Consumer.class);
53+
gatewayProxyFactoryBean.setDefaultRequestChannelName("logConsumerFlow.input");
54+
return (AnnotationGatewayProxyFactoryBean) gatewayProxyFactoryBean;
5255
}
5356

5457
}

consumer/spring-sftp-consumer/src/main/java/org/springframework/cloud/fn/consumer/sftp/SftpConsumerConfiguration.java

+7-4
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
import org.springframework.cloud.fn.common.config.ComponentCustomizer;
2626
import org.springframework.context.annotation.Bean;
2727
import org.springframework.context.annotation.Import;
28-
import org.springframework.integration.annotation.MessagingGateway;
2928
import org.springframework.integration.dsl.IntegrationFlow;
3029
import org.springframework.integration.file.remote.session.SessionFactory;
30+
import org.springframework.integration.gateway.AnnotationGatewayProxyFactoryBean;
3131
import org.springframework.integration.sftp.dsl.Sftp;
3232
import org.springframework.integration.sftp.dsl.SftpMessageHandlerSpec;
3333
import org.springframework.integration.sftp.session.SftpRemoteFileTemplate;
@@ -69,9 +69,12 @@ public IntegrationFlow ftpOutboundFlow(SftpConsumerProperties properties,
6969
return (flow) -> flow.handle(handlerSpec);
7070
}
7171

72-
@MessagingGateway(name = "sftpConsumer", defaultRequestChannel = "ftpOutboundFlow.input")
73-
public interface MessageConsumer extends Consumer<Message<?>> {
74-
72+
@Bean
73+
@SuppressWarnings({ "unchecked", "rawtypes" })
74+
AnnotationGatewayProxyFactoryBean<Consumer<Message<?>>> sftpConsumer() {
75+
var gatewayProxyFactoryBean = new AnnotationGatewayProxyFactoryBean<>(Consumer.class);
76+
gatewayProxyFactoryBean.setDefaultRequestChannelName("ftpOutboundFlow.input");
77+
return (AnnotationGatewayProxyFactoryBean) gatewayProxyFactoryBean;
7578
}
7679

7780
}

0 commit comments

Comments
 (0)