Make spring-syslog-supplier as auto-configuration
* Fix `SyslogSupplierConfiguration` according to the `@AutoConfiguration` expectations * Fix all the Checkstyle violations in the `spring-syslog-supplier`
This commit is contained in:
@@ -7,7 +7,7 @@ Users have to subscribe to this `Flux` and receive the data.
|
||||
|
||||
## Beans for injection
|
||||
|
||||
You can import the `SyslogSupplierConfiguration` in the application and then inject the following bean.
|
||||
The `SyslogSupplierConfiguration` provides the following bean:
|
||||
|
||||
`syslogSupplier`
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2020-2021 the original author or authors.
|
||||
* Copyright 2020-2024 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.
|
||||
@@ -23,6 +23,7 @@ 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;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -43,11 +44,11 @@ import org.springframework.integration.syslog.inbound.UdpSyslogReceivingChannelA
|
||||
import org.springframework.messaging.Message;
|
||||
|
||||
/**
|
||||
* Configuration class for SYSLOG Supplier.
|
||||
* Auto-configuration class for SYSLOG Supplier.
|
||||
*
|
||||
* @author Soby Chacko
|
||||
*/
|
||||
@Configuration
|
||||
@AutoConfiguration
|
||||
@EnableConfigurationProperties(SyslogSupplierProperties.class)
|
||||
public class SyslogSupplierConfiguration {
|
||||
|
||||
@@ -60,12 +61,13 @@ public class SyslogSupplierConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Supplier<Flux<Message<?>>> syslogSupplier(
|
||||
public Supplier<Flux<Message<?>>> syslogSupplier(FluxMessageChannel syslogInputChannel,
|
||||
ObjectProvider<UdpSyslogReceivingChannelAdapter> udpAdapterProvider,
|
||||
ObjectProvider<TcpSyslogReceivingChannelAdapter> tcpAdapterProvider) {
|
||||
return () -> Flux.from(syslogInputChannel()).doOnSubscribe(subscription -> {
|
||||
final UdpSyslogReceivingChannelAdapter udpAdapter = udpAdapterProvider.getIfAvailable();
|
||||
final TcpSyslogReceivingChannelAdapter tcpAdapter = tcpAdapterProvider.getIfAvailable();
|
||||
|
||||
return () -> Flux.from(syslogInputChannel).doOnSubscribe((subscription) -> {
|
||||
UdpSyslogReceivingChannelAdapter udpAdapter = udpAdapterProvider.getIfAvailable();
|
||||
TcpSyslogReceivingChannelAdapter tcpAdapter = tcpAdapterProvider.getIfAvailable();
|
||||
if (udpAdapter != null) {
|
||||
udpAdapter.start();
|
||||
}
|
||||
@@ -77,34 +79,44 @@ public class SyslogSupplierConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnProperty(name = "syslog.supplier.protocol", havingValue = "udp")
|
||||
public UdpSyslogReceivingChannelAdapter udpAdapter() {
|
||||
return createUdpAdapter();
|
||||
public UdpSyslogReceivingChannelAdapter udpAdapter(MessageConverter syslogConverter,
|
||||
FluxMessageChannel syslogInputChannel) {
|
||||
|
||||
return createUdpAdapter(syslogConverter, syslogInputChannel);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnProperty(name = "syslog.supplier.protocol", havingValue = "both")
|
||||
public UdpSyslogReceivingChannelAdapter udpBothAdapter() {
|
||||
return createUdpAdapter();
|
||||
public UdpSyslogReceivingChannelAdapter udpBothAdapter(MessageConverter syslogConverter,
|
||||
FluxMessageChannel syslogInputChannel) {
|
||||
|
||||
return createUdpAdapter(syslogConverter, syslogInputChannel);
|
||||
}
|
||||
|
||||
private UdpSyslogReceivingChannelAdapter createUdpAdapter() {
|
||||
private UdpSyslogReceivingChannelAdapter createUdpAdapter(MessageConverter syslogConverter,
|
||||
FluxMessageChannel syslogInputChannel) {
|
||||
|
||||
UdpSyslogReceivingChannelAdapter adapter = new UdpSyslogReceivingChannelAdapter();
|
||||
setAdapterProperties(adapter);
|
||||
setAdapterProperties(adapter, syslogConverter, syslogInputChannel);
|
||||
return adapter;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnProperty(name = "syslog.supplier.protocol", havingValue = "tcp", matchIfMissing = true)
|
||||
public TcpSyslogReceivingChannelAdapter tcpAdapter(
|
||||
@Qualifier("syslogSupplierConnectionFactory") AbstractServerConnectionFactory connectionFactory) {
|
||||
return createTcpAdapter(connectionFactory);
|
||||
@Qualifier("syslogSupplierConnectionFactory") AbstractServerConnectionFactory connectionFactory,
|
||||
MessageConverter syslogConverter, FluxMessageChannel syslogInputChannel) {
|
||||
|
||||
return createTcpAdapter(connectionFactory, syslogConverter, syslogInputChannel);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnProperty(name = "syslog.supplier.protocol", havingValue = "both")
|
||||
public TcpSyslogReceivingChannelAdapter tcpBothAdapter(
|
||||
@Qualifier("syslogSupplierConnectionFactory") AbstractServerConnectionFactory connectionFactory) {
|
||||
return createTcpAdapter(connectionFactory);
|
||||
@Qualifier("syslogSupplierConnectionFactory") AbstractServerConnectionFactory connectionFactory,
|
||||
MessageConverter syslogConverter, FluxMessageChannel syslogInputChannel) {
|
||||
|
||||
return createTcpAdapter(connectionFactory, syslogConverter, syslogInputChannel);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -117,21 +129,25 @@ public class SyslogSupplierConfiguration {
|
||||
}
|
||||
}
|
||||
|
||||
private TcpSyslogReceivingChannelAdapter createTcpAdapter(AbstractServerConnectionFactory connectionFactory) {
|
||||
private TcpSyslogReceivingChannelAdapter createTcpAdapter(AbstractServerConnectionFactory connectionFactory,
|
||||
MessageConverter syslogConverter, FluxMessageChannel syslogInputChannel) {
|
||||
|
||||
TcpSyslogReceivingChannelAdapter adapter = new TcpSyslogReceivingChannelAdapter();
|
||||
adapter.setConnectionFactory(connectionFactory);
|
||||
setAdapterProperties(adapter);
|
||||
setAdapterProperties(adapter, syslogConverter, syslogInputChannel);
|
||||
return adapter;
|
||||
}
|
||||
|
||||
private void setAdapterProperties(SyslogReceivingChannelAdapterSupport adapter) {
|
||||
private void setAdapterProperties(SyslogReceivingChannelAdapterSupport adapter, MessageConverter syslogConverter,
|
||||
FluxMessageChannel syslogInputChannel) {
|
||||
|
||||
adapter.setPort(this.properties.getPort());
|
||||
adapter.setConverter(syslogConverter());
|
||||
adapter.setOutputChannel(syslogInputChannel());
|
||||
adapter.setConverter(syslogConverter);
|
||||
adapter.setOutputChannel(syslogInputChannel);
|
||||
adapter.setAutoStartup(false);
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnProperty(name = "syslog.supplier.protocol", havingValue = "tcp", matchIfMissing = true)
|
||||
protected static class TcpBits {
|
||||
|
||||
@@ -140,7 +156,8 @@ public class SyslogSupplierConfiguration {
|
||||
|
||||
@Bean
|
||||
public AbstractServerConnectionFactory syslogSupplierConnectionFactory(
|
||||
@Qualifier("syslogSupplierDecoder") Deserializer<?> decoder) throws Exception {
|
||||
@Qualifier("syslogSupplierDecoder") Deserializer<?> decoder) {
|
||||
|
||||
AbstractServerConnectionFactory factory;
|
||||
if (this.properties.isNio()) {
|
||||
factory = new TcpNioServerConnectionFactory(this.properties.getPort());
|
||||
@@ -168,7 +185,7 @@ public class SyslogSupplierConfiguration {
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnProperty(name = "syslog.supplier.protocol", havingValue = "both")
|
||||
protected static class BothBits extends TcpBits {
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016-2020 the original author or authors.
|
||||
* Copyright 2016-2024 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.
|
||||
@@ -22,6 +22,11 @@ import jakarta.validation.constraints.NotNull;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
/**
|
||||
* The configuration properties for Syslog supplier.
|
||||
*
|
||||
* @author Soby Chacko
|
||||
*/
|
||||
@ConfigurationProperties("syslog.supplier")
|
||||
@Validated
|
||||
public class SyslogSupplierProperties {
|
||||
@@ -42,28 +47,28 @@ public class SyslogSupplierProperties {
|
||||
private int port = 1514;
|
||||
|
||||
/**
|
||||
* whether or not to use NIO (when supporting a large number of connections).
|
||||
* Whether to use NIO (when supporting a large number of connections).
|
||||
*/
|
||||
private boolean nio = false;
|
||||
|
||||
/**
|
||||
* whether or not to perform a reverse lookup on the incoming socket.
|
||||
* Whether to perform a reverse lookup on the incoming socket.
|
||||
*/
|
||||
private boolean reverseLookup;
|
||||
|
||||
/**
|
||||
* the socket timeout.
|
||||
* The socket timeout.
|
||||
*/
|
||||
private int socketTimeout;
|
||||
|
||||
/**
|
||||
* '5424' or '3164' - the syslog format according to the RFC; 3164 is aka 'BSD'
|
||||
* The '5424' or '3164' - the syslog format according to the RFC; 3164 is aka 'BSD'
|
||||
* format.
|
||||
*/
|
||||
private String rfc = "3164";
|
||||
|
||||
public int getBufferSize() {
|
||||
return bufferSize;
|
||||
return this.bufferSize;
|
||||
}
|
||||
|
||||
public void setBufferSize(int bufferSize) {
|
||||
@@ -71,7 +76,7 @@ public class SyslogSupplierProperties {
|
||||
}
|
||||
|
||||
public Protocol getProtocol() {
|
||||
return protocol;
|
||||
return this.protocol;
|
||||
}
|
||||
|
||||
public void setProtocol(Protocol protocol) {
|
||||
@@ -79,7 +84,7 @@ public class SyslogSupplierProperties {
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
return port;
|
||||
return this.port;
|
||||
}
|
||||
|
||||
public void setPort(int port) {
|
||||
@@ -87,7 +92,7 @@ public class SyslogSupplierProperties {
|
||||
}
|
||||
|
||||
public boolean isNio() {
|
||||
return nio;
|
||||
return this.nio;
|
||||
}
|
||||
|
||||
public void setNio(boolean nio) {
|
||||
@@ -95,7 +100,7 @@ public class SyslogSupplierProperties {
|
||||
}
|
||||
|
||||
public boolean isReverseLookup() {
|
||||
return reverseLookup;
|
||||
return this.reverseLookup;
|
||||
}
|
||||
|
||||
public void setReverseLookup(boolean reverseLookup) {
|
||||
@@ -103,7 +108,7 @@ public class SyslogSupplierProperties {
|
||||
}
|
||||
|
||||
public int getSocketTimeout() {
|
||||
return socketTimeout;
|
||||
return this.socketTimeout;
|
||||
}
|
||||
|
||||
public void setSocketTimeout(int socketTimeout) {
|
||||
@@ -112,7 +117,7 @@ public class SyslogSupplierProperties {
|
||||
|
||||
@NotNull
|
||||
public String getRfc() {
|
||||
return rfc;
|
||||
return this.rfc;
|
||||
}
|
||||
|
||||
public void setRfc(String rfc) {
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
/**
|
||||
* The Syslog supplier auto-configuration support.
|
||||
*/
|
||||
package org.springframework.cloud.fn.supplier.syslog;
|
||||
@@ -0,0 +1 @@
|
||||
org.springframework.cloud.fn.supplier.syslog.SyslogSupplierConfiguration
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016-2020 the original author or authors.
|
||||
* Copyright 2016-2024 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.
|
||||
@@ -32,9 +32,10 @@ public class Tcp3164Tests extends AbstractSyslogSupplierTests {
|
||||
public void test() throws Exception {
|
||||
final Flux<Message<?>> messageFlux = syslogSupplier.get();
|
||||
|
||||
final StepVerifier stepVerifier = StepVerifier.create(messageFlux).assertNext((message) -> {
|
||||
assertThat(((Map) message.getPayload()).get("HOST")).isEqualTo("WEBERN");
|
||||
}).thenCancel().verifyLater();
|
||||
final StepVerifier stepVerifier = StepVerifier.create(messageFlux)
|
||||
.assertNext((message) -> assertThat(((Map<?, ?>) message.getPayload()).get("HOST")).isEqualTo("WEBERN"))
|
||||
.thenCancel()
|
||||
.verifyLater();
|
||||
|
||||
sendTcp(AbstractSyslogSupplierTests.RFC3164_PACKET + "\n");
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016-2020 the original author or authors.
|
||||
* Copyright 2016-2024 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.
|
||||
@@ -34,9 +34,11 @@ public class Tcp5424Tests extends AbstractSyslogSupplierTests {
|
||||
public void test() throws Exception {
|
||||
final Flux<Message<?>> messageFlux = syslogSupplier.get();
|
||||
|
||||
final StepVerifier stepVerifier = StepVerifier.create(messageFlux).assertNext((message) -> {
|
||||
assertThat(((Map) message.getPayload()).get("syslog_HOST")).isEqualTo("loggregator");
|
||||
}).thenCancel().verifyLater();
|
||||
final StepVerifier stepVerifier = StepVerifier.create(messageFlux)
|
||||
.assertNext((message) -> assertThat(((Map<?, ?>) message.getPayload()).get("syslog_HOST"))
|
||||
.isEqualTo("loggregator"))
|
||||
.thenCancel()
|
||||
.verifyLater();
|
||||
|
||||
sendTcp("253 " + RFC5424_PACKET);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016-2020 the original author or authors.
|
||||
* Copyright 2016-2024 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.
|
||||
@@ -33,11 +33,11 @@ public class TcpAndUdp3164Tests extends AbstractSyslogSupplierTests {
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
final Flux<Message<?>> messageFlux = syslogSupplier.get();
|
||||
final StepVerifier stepVerifier = StepVerifier.create(messageFlux).assertNext((message) -> {
|
||||
assertThat(((Map) message.getPayload()).get("HOST")).isEqualTo("WEBERN");
|
||||
}).assertNext((message) -> {
|
||||
assertThat(((Map) message.getPayload()).get("HOST")).isEqualTo("WEBERN");
|
||||
}).thenCancel().verifyLater();
|
||||
final StepVerifier stepVerifier = StepVerifier.create(messageFlux)
|
||||
.assertNext((message) -> assertThat(((Map<?, ?>) message.getPayload()).get("HOST")).isEqualTo("WEBERN"))
|
||||
.assertNext((message) -> assertThat(((Map<?, ?>) message.getPayload()).get("HOST")).isEqualTo("WEBERN"))
|
||||
.thenCancel()
|
||||
.verifyLater();
|
||||
|
||||
sendTcp(RFC3164_PACKET + "\n");
|
||||
sendUdp(RFC3164_PACKET);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016-2020 the original author or authors.
|
||||
* Copyright 2016-2024 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.
|
||||
@@ -33,11 +33,13 @@ public class TcpAndUdp5424Tests extends AbstractSyslogSupplierTests {
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
final Flux<Message<?>> messageFlux = syslogSupplier.get();
|
||||
final StepVerifier stepVerifier = StepVerifier.create(messageFlux).assertNext((message) -> {
|
||||
assertThat(((Map) message.getPayload()).get("syslog_HOST")).isEqualTo("loggregator");
|
||||
}).assertNext((message) -> {
|
||||
assertThat(((Map) message.getPayload()).get("syslog_HOST")).isEqualTo("loggregator");
|
||||
}).thenCancel().verifyLater();
|
||||
final StepVerifier stepVerifier = StepVerifier.create(messageFlux)
|
||||
.assertNext((message) -> assertThat(((Map<?, ?>) message.getPayload()).get("syslog_HOST"))
|
||||
.isEqualTo("loggregator"))
|
||||
.assertNext((message) -> assertThat(((Map<?, ?>) message.getPayload()).get("syslog_HOST"))
|
||||
.isEqualTo("loggregator"))
|
||||
.thenCancel()
|
||||
.verifyLater();
|
||||
|
||||
sendTcp("253 " + RFC5424_PACKET);
|
||||
sendUdp(RFC5424_PACKET);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016-2020 the original author or authors.
|
||||
* Copyright 2016-2024 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.
|
||||
@@ -34,9 +34,10 @@ public class Udp3164Tests extends AbstractSyslogSupplierTests {
|
||||
public void test() throws Exception {
|
||||
final Flux<Message<?>> messageFlux = syslogSupplier.get();
|
||||
|
||||
final StepVerifier stepVerifier = StepVerifier.create(messageFlux).assertNext((message) -> {
|
||||
assertThat(((Map) message.getPayload()).get("HOST")).isEqualTo("WEBERN");
|
||||
}).thenCancel().verifyLater();
|
||||
final StepVerifier stepVerifier = StepVerifier.create(messageFlux)
|
||||
.assertNext((message) -> assertThat(((Map<?, ?>) message.getPayload()).get("HOST")).isEqualTo("WEBERN"))
|
||||
.thenCancel()
|
||||
.verifyLater();
|
||||
|
||||
sendUdp(RFC3164_PACKET);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016-2020 the original author or authors.
|
||||
* Copyright 2016-2024 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.
|
||||
@@ -33,9 +33,11 @@ public class Udp5424Tests extends AbstractSyslogSupplierTests {
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
final Flux<Message<?>> messageFlux = syslogSupplier.get();
|
||||
final StepVerifier stepVerifier = StepVerifier.create(messageFlux).assertNext((message) -> {
|
||||
assertThat(((Map) message.getPayload()).get("syslog_HOST")).isEqualTo("loggregator");
|
||||
}).thenCancel().verifyLater();
|
||||
final StepVerifier stepVerifier = StepVerifier.create(messageFlux)
|
||||
.assertNext((message) -> assertThat(((Map<?, ?>) message.getPayload()).get("syslog_HOST"))
|
||||
.isEqualTo("loggregator"))
|
||||
.thenCancel()
|
||||
.verifyLater();
|
||||
|
||||
sendUdp(RFC5424_PACKET);
|
||||
stepVerifier.verify();
|
||||
|
||||
Reference in New Issue
Block a user