From d7a6c1e1ec073b4d0ae8e186c047338e396deebb Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Thu, 19 Dec 2024 16:23:02 -0500 Subject: [PATCH] GH-121: Fix auto-wiring ambiguity in the `SyslogSupplierConfiguration` Fixes: https://github.com/spring-cloud/spring-functions-catalog/issues/121 --- .../syslog/SyslogSupplierConfiguration.java | 28 +++++++++---------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/supplier/spring-syslog-supplier/src/main/java/org/springframework/cloud/fn/supplier/syslog/SyslogSupplierConfiguration.java b/supplier/spring-syslog-supplier/src/main/java/org/springframework/cloud/fn/supplier/syslog/SyslogSupplierConfiguration.java index 885b311d..058c8eed 100644 --- a/supplier/spring-syslog-supplier/src/main/java/org/springframework/cloud/fn/supplier/syslog/SyslogSupplierConfiguration.java +++ b/supplier/spring-syslog-supplier/src/main/java/org/springframework/cloud/fn/supplier/syslog/SyslogSupplierConfiguration.java @@ -20,7 +20,6 @@ import reactor.core.publisher.Flux; -import org.springframework.beans.factory.ObjectProvider; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.autoconfigure.AutoConfiguration; @@ -41,6 +40,7 @@ import org.springframework.integration.syslog.inbound.SyslogReceivingChannelAdapterSupport; import org.springframework.integration.syslog.inbound.TcpSyslogReceivingChannelAdapter; import org.springframework.integration.syslog.inbound.UdpSyslogReceivingChannelAdapter; +import org.springframework.lang.Nullable; import org.springframework.messaging.Message; /** @@ -59,28 +59,26 @@ public class SyslogSupplierConfiguration { @Bean public Supplier>> syslogSupplier( - ObjectProvider udpAdapterProvider, - ObjectProvider tcpAdapterProvider) { - - return () -> Flux.from(this.syslogInputChannel).doOnSubscribe((subscription) -> { - UdpSyslogReceivingChannelAdapter udpAdapter = udpAdapterProvider.getIfAvailable(); - TcpSyslogReceivingChannelAdapter tcpAdapter = tcpAdapterProvider.getIfAvailable(); - if (udpAdapter != null) { - udpAdapter.start(); + @Nullable UdpSyslogReceivingChannelAdapter udpSyslogReceivingChannelAdapter, + @Nullable TcpSyslogReceivingChannelAdapter tcpSyslogReceivingChannelAdapter) { + + return () -> Flux.from(this.syslogInputChannel).doOnRequest((l) -> { + if (udpSyslogReceivingChannelAdapter != null) { + udpSyslogReceivingChannelAdapter.start(); } - if (tcpAdapter != null) { - tcpAdapter.start(); + if (tcpSyslogReceivingChannelAdapter != null) { + tcpSyslogReceivingChannelAdapter.start(); } }); } - @Bean + @Bean("udpSyslogReceivingChannelAdapter") @ConditionalOnProperty(name = "syslog.supplier.protocol", havingValue = "udp") public UdpSyslogReceivingChannelAdapter udpAdapter(MessageConverter syslogConverter) { return createUdpAdapter(syslogConverter); } - @Bean + @Bean("udpSyslogReceivingChannelAdapter") @ConditionalOnProperty(name = "syslog.supplier.protocol", havingValue = "both") public UdpSyslogReceivingChannelAdapter udpBothAdapter(MessageConverter syslogConverter) { return createUdpAdapter(syslogConverter); @@ -92,7 +90,7 @@ private UdpSyslogReceivingChannelAdapter createUdpAdapter(MessageConverter syslo return adapter; } - @Bean + @Bean("tcpSyslogReceivingChannelAdapter") @ConditionalOnProperty(name = "syslog.supplier.protocol", havingValue = "tcp", matchIfMissing = true) public TcpSyslogReceivingChannelAdapter tcpAdapter( @Qualifier("syslogSupplierConnectionFactory") AbstractServerConnectionFactory connectionFactory, @@ -101,7 +99,7 @@ public TcpSyslogReceivingChannelAdapter tcpAdapter( return createTcpAdapter(connectionFactory, syslogConverter); } - @Bean + @Bean("tcpSyslogReceivingChannelAdapter") @ConditionalOnProperty(name = "syslog.supplier.protocol", havingValue = "both") public TcpSyslogReceivingChannelAdapter tcpBothAdapter( @Qualifier("syslogSupplierConnectionFactory") AbstractServerConnectionFactory connectionFactory,