我正在 Spring Boot 1.5.6.RELEASE 中编写UDP syslog消息接收器,如果不添加spring-boot-starter-web
依赖项,它将关闭。问题是我不需要Web依赖,因为该应用程序仅通过TCP进一步接收,过滤和发送日志。我正在使用org.springframework.integration.syslog.inbound.UdpSyslogReceivingChannelAdapter
。
接收器:
@Bean
public UdpSyslogReceivingChannelAdapter udpReceiver() {
final UdpSyslogReceivingChannelAdapter adapter = new UdpSyslogReceivingChannelAdapter();
adapter.setPort(properties.getUdp().getLocalPort());
adapter.setOutputChannelName("routingChannel");
adapter.setConverter(converter);
return adapter;
}
这是控制台输出,没有任何异常:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.5.6.RELEASE)
2018-10-05 08:55:18.338 INFO 21016 --- [ main] h.b.iptv.stream.IptvStreamApplication : Starting IptvStreamApplication on DESKTOP-0S65L7N with PID 21016 (D:\Projects\iptv\iptv-stream\target\classes started by tomiv in D:\Projects\iptv)
2018-10-05 08:55:18.342 INFO 21016 --- [ main] h.b.iptv.stream.IptvStreamApplication : No active profile set, falling back to default profiles: default
2018-10-05 08:55:18.386 INFO 21016 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@384ad17b: startup date [Fri Oct 05 08:55:18 CEST 2018]; root of context hierarchy
2018-10-05 08:55:19.325 INFO 21016 --- [ main] o.s.i.config.IntegrationRegistrar : No bean named 'integrationHeaderChannelRegistry' has been explicitly defined. Therefore, a default DefaultHeaderChannelRegistry will be created.
2018-10-05 08:55:19.400 INFO 21016 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
2018-10-05 08:55:19.546 INFO 21016 --- [ main] faultConfiguringBeanFactoryPostProcessor : No bean named 'errorChannel' has been explicitly defined. Therefore, a default PublishSubscribeChannel will be created.
2018-10-05 08:55:19.552 INFO 21016 --- [ main] faultConfiguringBeanFactoryPostProcessor : No bean named 'taskScheduler' has been explicitly defined. Therefore, a default ThreadPoolTaskScheduler will be created.
2018-10-05 08:55:19.674 INFO 21016 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'integrationGlobalProperties' of type [org.springframework.beans.factory.config.PropertiesFactoryBean] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-10-05 08:55:19.678 INFO 21016 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'integrationGlobalProperties' of type [java.util.Properties] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-10-05 08:55:19.986 INFO 21016 --- [ main] o.s.s.c.ThreadPoolTaskScheduler : Initializing ExecutorService 'taskScheduler'
2018-10-05 08:55:20.064 INFO 21016 --- [ main] redis.clients.jedis.JedisSentinelPool : Trying to find master from available Sentinels...
2018-10-05 08:55:20.082 INFO 21016 --- [ main] redis.clients.jedis.JedisSentinelPool : Redis master running at 10.10.20.49:6379, starting Sentinel listeners...
2018-10-05 08:55:20.091 INFO 21016 --- [ main] redis.clients.jedis.JedisSentinelPool : Created JedisPool to master at 10.10.20.49:6379
2018-10-05 08:55:20.093 INFO 21016 --- [ main] redis.clients.jedis.JedisSentinelPool : Trying to find master from available Sentinels...
2018-10-05 08:55:20.096 INFO 21016 --- [ main] redis.clients.jedis.JedisSentinelPool : Redis master running at 10.10.20.49:6379, starting Sentinel listeners...
2018-10-05 08:55:20.097 INFO 21016 --- [ main] redis.clients.jedis.JedisSentinelPool : Created JedisPool to master at 10.10.20.49:6379
2018-10-05 08:55:20.097 INFO 21016 --- [ main] redis.clients.jedis.JedisSentinelPool : Trying to find master from available Sentinels...
2018-10-05 08:55:20.099 INFO 21016 --- [ main] redis.clients.jedis.JedisSentinelPool : Redis master running at 10.10.20.49:6379, starting Sentinel listeners...
2018-10-05 08:55:20.100 INFO 21016 --- [ main] redis.clients.jedis.JedisSentinelPool : Created JedisPool to master at 10.10.20.49:6379
2018-10-05 08:55:20.400 INFO 21016 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2018-10-05 08:55:20.405 INFO 21016 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'payloadHandlingService.route.router.handler' has been autodetected for JMX exposure
2018-10-05 08:55:20.406 INFO 21016 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Located managed bean 'payloadHandlingService.route.router.handler': registering with JMX server as MBean [org.springframework.integration.router:name=payloadHandlingService.route.router.handler,type=MethodInvokingRouter]
2018-10-05 08:55:20.460 INFO 21016 --- [ main] o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase -2147483648
2018-10-05 08:55:20.460 INFO 21016 --- [ main] o.s.i.endpoint.EventDrivenConsumer : Adding {message-handler:streamConfiguration.handler.serviceActivator} as a subscriber to the 'udpOut' channel
2018-10-05 08:55:20.460 INFO 21016 --- [ main] o.s.integration.channel.DirectChannel : Channel 'application.udpOut' has 1 subscriber(s).
2018-10-05 08:55:20.460 INFO 21016 --- [ main] o.s.i.endpoint.EventDrivenConsumer : started streamConfiguration.handler.serviceActivator
2018-10-05 08:55:20.460 INFO 21016 --- [ main] o.s.i.endpoint.EventDrivenConsumer : Adding {message-handler:streamConfiguration.tcpSender.serviceActivator} as a subscriber to the 'tcpOut' channel
2018-10-05 08:55:20.460 INFO 21016 --- [ main] o.s.integration.channel.DirectChannel : Channel 'application.tcpOut' has 1 subscriber(s).
2018-10-05 08:55:20.460 INFO 21016 --- [ main] .s.i.i.t.c.TcpNetClientConnectionFactory : started tcpConnectionFactory, host=localhost, port=3333
2018-10-05 08:55:20.460 INFO 21016 --- [ main] o.s.i.endpoint.EventDrivenConsumer : started streamConfiguration.tcpSender.serviceActivator
2018-10-05 08:55:20.460 INFO 21016 --- [ main] o.s.i.endpoint.EventDrivenConsumer : Adding {router:payloadHandlingService.route.router} as a subscriber to the 'routingChannel' channel
2018-10-05 08:55:20.460 INFO 21016 --- [ main] o.s.integration.channel.DirectChannel : Channel 'application.routingChannel' has 1 subscriber(s).
2018-10-05 08:55:20.460 INFO 21016 --- [ main] o.s.i.endpoint.EventDrivenConsumer : started payloadHandlingService.route.router
2018-10-05 08:55:20.460 INFO 21016 --- [ main] o.s.i.endpoint.EventDrivenConsumer : Adding {service-activator:payloadHandlingService.handleAvrPayload.serviceActivator} as a subscriber to the 'anonymizationChannel' channel
2018-10-05 08:55:20.461 INFO 21016 --- [ main] o.s.integration.channel.DirectChannel : Channel 'application.anonymizationChannel' has 1 subscriber(s).
2018-10-05 08:55:20.461 INFO 21016 --- [ main] o.s.i.endpoint.EventDrivenConsumer : started payloadHandlingService.handleAvrPayload.serviceActivator
2018-10-05 08:55:20.461 INFO 21016 --- [ main] o.s.i.endpoint.EventDrivenConsumer : Adding {service-activator:payloadHandlingService.handleUdpProbePayload.serviceActivator} as a subscriber to the 'loadBalancerChannel' channel
2018-10-05 08:55:20.461 INFO 21016 --- [ main] o.s.integration.channel.DirectChannel : Channel 'application.loadBalancerChannel' has 1 subscriber(s).
2018-10-05 08:55:20.461 INFO 21016 --- [ main] o.s.i.endpoint.EventDrivenConsumer : started payloadHandlingService.handleUdpProbePayload.serviceActivator
2018-10-05 08:55:20.463 INFO 21016 --- [ main] o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase 0
2018-10-05 08:55:20.463 INFO 21016 --- [ main] o.s.i.endpoint.EventDrivenConsumer : Adding {logging-channel-adapter:_org.springframework.integration.errorLogger} as a subscriber to the 'errorChannel' channel
2018-10-05 08:55:20.463 INFO 21016 --- [ main] o.s.i.channel.PublishSubscribeChannel : Channel 'application.errorChannel' has 1 subscriber(s).
2018-10-05 08:55:20.463 INFO 21016 --- [ main] o.s.i.endpoint.EventDrivenConsumer : started _org.springframework.integration.errorLogger
2018-10-05 08:55:20.463 INFO 21016 --- [ main] o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase 1073741823
2018-10-05 08:55:20.464 INFO 21016 --- [ main] o.s.i.i.u.UnicastReceivingChannelAdapter : started org.springframework.integration.ip.udp.UnicastReceivingChannelAdapter@70887727
2018-10-05 08:55:20.464 INFO 21016 --- [ main] s.i.s.i.UdpSyslogReceivingChannelAdapter : started udpReceiver
2018-10-05 08:55:20.471 INFO 21016 --- [ main] h.b.iptv.stream.IptvStreamApplication : Started IptvStreamApplication in 2.421 seconds (JVM running for 3.548)
2018-10-05 08:55:20.472 INFO 21016 --- [ Thread-10] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@384ad17b: startup date [Fri Oct 05 08:55:18 CEST 2018]; root of context hierarchy
2018-10-05 08:55:20.473 INFO 21016 --- [ Thread-10] o.s.c.support.DefaultLifecycleProcessor : Stopping beans in phase 1073741823
2018-10-05 08:55:20.474 INFO 21016 --- [ Thread-10] o.s.i.i.u.UnicastReceivingChannelAdapter : stopped org.springframework.integration.ip.udp.UnicastReceivingChannelAdapter@70887727
2018-10-05 08:55:20.474 INFO 21016 --- [ Thread-10] s.i.s.i.UdpSyslogReceivingChannelAdapter : stopped udpReceiver
2018-10-05 08:55:20.474 INFO 21016 --- [ Thread-10] o.s.c.support.DefaultLifecycleProcessor : Stopping beans in phase 0
2018-10-05 08:55:20.474 INFO 21016 --- [ Thread-10] .s.i.i.t.c.TcpNetClientConnectionFactory : stopped tcpConnectionFactory, host=localhost, port=3333
2018-10-05 08:55:20.474 INFO 21016 --- [ Thread-10] o.s.i.endpoint.EventDrivenConsumer : Removing {logging-channel-adapter:_org.springframework.integration.errorLogger} as a subscriber to the 'errorChannel' channel
2018-10-05 08:55:20.474 INFO 21016 --- [ Thread-10] o.s.i.channel.PublishSubscribeChannel : Channel 'application.errorChannel' has 0 subscriber(s).
2018-10-05 08:55:20.474 INFO 21016 --- [ Thread-10] o.s.i.endpoint.EventDrivenConsumer : stopped _org.springframework.integration.errorLogger
2018-10-05 08:55:20.474 INFO 21016 --- [ Thread-10] o.s.c.support.DefaultLifecycleProcessor : Stopping beans in phase -2147483648
2018-10-05 08:55:20.474 INFO 21016 --- [ Thread-10] o.s.i.endpoint.EventDrivenConsumer : Removing {message-handler:streamConfiguration.handler.serviceActivator} as a subscriber to the 'udpOut' channel
2018-10-05 08:55:20.474 INFO 21016 --- [ Thread-10] o.s.integration.channel.DirectChannel : Channel 'application.udpOut' has 0 subscriber(s).
2018-10-05 08:55:20.474 INFO 21016 --- [ Thread-10] o.s.i.endpoint.EventDrivenConsumer : stopped streamConfiguration.handler.serviceActivator
2018-10-05 08:55:20.474 INFO 21016 --- [ Thread-10] o.s.i.endpoint.EventDrivenConsumer : Removing {message-handler:streamConfiguration.tcpSender.serviceActivator} as a subscriber to the 'tcpOut' channel
2018-10-05 08:55:20.475 INFO 21016 --- [ Thread-10] o.s.integration.channel.DirectChannel : Channel 'application.tcpOut' has 0 subscriber(s).
2018-10-05 08:55:20.475 INFO 21016 --- [ Thread-10] o.s.i.endpoint.EventDrivenConsumer : stopped streamConfiguration.tcpSender.serviceActivator
2018-10-05 08:55:20.475 INFO 21016 --- [ Thread-10] o.s.i.endpoint.EventDrivenConsumer : Removing {router:payloadHandlingService.route.router} as a subscriber to the 'routingChannel' channel
2018-10-05 08:55:20.475 INFO 21016 --- [ Thread-10] o.s.integration.channel.DirectChannel : Channel 'application.routingChannel' has 0 subscriber(s).
2018-10-05 08:55:20.475 INFO 21016 --- [ Thread-10] o.s.i.endpoint.EventDrivenConsumer : stopped payloadHandlingService.route.router
2018-10-05 08:55:20.476 INFO 21016 --- [ Thread-10] o.s.i.endpoint.EventDrivenConsumer : Removing {service-activator:payloadHandlingService.handleAvrPayload.serviceActivator} as a subscriber to the 'anonymizationChannel' channel
2018-10-05 08:55:20.476 INFO 21016 --- [ Thread-10] o.s.integration.channel.DirectChannel : Channel 'application.anonymizationChannel' has 0 subscriber(s).
2018-10-05 08:55:20.476 INFO 21016 --- [ Thread-10] o.s.i.endpoint.EventDrivenConsumer : stopped payloadHandlingService.handleAvrPayload.serviceActivator
2018-10-05 08:55:20.476 INFO 21016 --- [ Thread-10] o.s.i.endpoint.EventDrivenConsumer : Removing {service-activator:payloadHandlingService.handleUdpProbePayload.serviceActivator} as a subscriber to the 'loadBalancerChannel' channel
2018-10-05 08:55:20.476 INFO 21016 --- [ Thread-10] o.s.integration.channel.DirectChannel : Channel 'application.loadBalancerChannel' has 0 subscriber(s).
2018-10-05 08:55:20.476 INFO 21016 --- [ Thread-10] o.s.i.endpoint.EventDrivenConsumer : stopped payloadHandlingService.handleUdpProbePayload.serviceActivator
2018-10-05 08:55:20.476 INFO 21016 --- [ Thread-10] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
2018-10-05 08:55:20.476 INFO 21016 --- [ Thread-10] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans
2018-10-05 08:55:20.477 INFO 21016 --- [ Thread-10] o.s.s.c.ThreadPoolTaskScheduler : Shutting down ExecutorService 'taskScheduler'
Process finished with exit code 0
在调试时,我尝试使用org.springframework.integration.syslog.inbound.TcpSyslogReceivingChannelAdapter
,即使未添加Web依赖项,应用程序也不会关闭。使用org.springframework.integration.syslog.inbound.UdpSyslogReceivingChannelAdapter
时应用程序关闭的原因是什么?我可以使用没有spring-boot-starter-web
依赖性的UdpSyslogReceivingChannelAdapter吗?
答案 0 :(得分:0)
默认情况下,基础UDP适配器使用守护程序线程(守护程序线程不会阻止JVM退出)。
您可以提供不使用守护程序线程的其他任务执行器...
@Bean
public UdpSyslogReceivingChannelAdapter udpReceiver() {
final UdpSyslogReceivingChannelAdapter adapter = new UdpSyslogReceivingChannelAdapter();
adapter.setUdpAdapter(receiver());
adapter.setOutputChannelName("routingChannel");
adapter.setConverter(converter);
return adapter;
}
@Bean
public UnicastReceivingChannelAdapter receiver() {
UnicastReceivingChannelAdapter adapter = new UnicastReceivingChannelAdapter(properties.getUdp().getLocalPort());
adapter.setTaskExecutor(executor());
return adapter;
}
@Bean
public TaskExecutor executor() {
ThreadPoolTaskExecutor exec = new ThreadPoolTaskExecutor();
exec.setCorePoolSize(5);
return exec;
}