猿问

Spring boot Syslog UDP 接收器关闭

我正在Spring Boot 1.5.6.RELEASE 中编写一个 UDP syslog 消息接收器,如果我不添加spring-boot-starter-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;

  }

在调试时,我尝试使用org.springframework.integration.syslog.inbound.TcpSyslogReceivingChannelAdapter,即使未添加 Web 依赖项,应用程序也不会关闭。应用程序在使用时关闭的原因是什么org.springframework.integration.syslog.inbound.UdpSyslogReceivingChannelAdapter?我可以在没有spring-boot-starter-web依赖的情况下使用 UdpSyslogReceivingChannelAdapter吗?

PIPIONE
浏览 403回答 1
1回答

回首忆惘然

底层 UDP 适配器默认使用守护线程(守护线程不阻止 JVM 退出)。您可以提供不使用守护线程的不同任务执行程序...@Beanpublic UdpSyslogReceivingChannelAdapter udpReceiver() {    final UdpSyslogReceivingChannelAdapter adapter = new UdpSyslogReceivingChannelAdapter();    adapter.setUdpAdapter(receiver());    adapter.setOutputChannelName("routingChannel");    adapter.setConverter(converter);    return adapter;}@Beanpublic UnicastReceivingChannelAdapter receiver() {    UnicastReceivingChannelAdapter adapter = new UnicastReceivingChannelAdapter(properties.getUdp().getLocalPort());    adapter.setTaskExecutor(executor());    return adapter;}@Beanpublic TaskExecutor executor() {    ThreadPoolTaskExecutor exec = new ThreadPoolTaskExecutor();    exec.setCorePoolSize(5);    return exec;}
随时随地看视频慕课网APP

相关分类

Java
我要回答