Skip to content

Commit

Permalink
GH-121: Fix auto-wiring ambiguity in the SyslogSupplierConfiguration
Browse files Browse the repository at this point in the history
Fixes: #121
  • Loading branch information
artembilan committed Dec 19, 2024
1 parent 6b0f058 commit d7a6c1e
Showing 1 changed file with 13 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

/**
Expand All @@ -59,28 +59,26 @@ public class SyslogSupplierConfiguration {

@Bean
public Supplier<Flux<Message<?>>> syslogSupplier(
ObjectProvider<UdpSyslogReceivingChannelAdapter> udpAdapterProvider,
ObjectProvider<TcpSyslogReceivingChannelAdapter> 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);
Expand All @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit d7a6c1e

Please sign in to comment.