为了账号安全,请及时绑定邮箱和手机立即绑定

Spring boot Syslog UDP 接收器关闭

Spring boot Syslog UDP 接收器关闭

PIPIONE 2021-10-28 14:01:26
我正在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吗?
查看完整描述

1 回答

?
回首忆惘然

TA贡献1847条经验 获得超11个赞

底层 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;

}


查看完整回答
反对 回复 2021-10-28
  • 1 回答
  • 0 关注
  • 402 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信