【问题标题】:Apache Camel based Udp server基于 Apache Camel 的 Udp 服务器
【发布时间】:2018-11-15 04:02:12
【问题描述】:

我正在尝试使用 Apache Camel 创建使用 syslog 消息的 udp 服务器。

没有正确的例子。

我编写了以下路由,使用自定义 serverInitializerFactory。

@Component
public class MainRoute extends RouteBuilder {

@Override
public void configure() throws Exception {
  from("netty4:udp://{{app.server.host}}:{{app.server.port}}?serverInitializerFactory=#udpSyslogFlowFactory&sync=false&textline=true")
    .to("seda:rowLogs");

  from("seda:rowLogs?concurrentConsumers={{app.concurrent-processors}}")
    .to("bean:logParser");
}

}

工厂代码:

@Component
public class UdpSyslogFlowFactory extends ServerInitializerFactory {

  private int maxLineSize = 1024;

  private NettyConsumer consumer;

  public UdpSyslogFlowFactory() {
    super();
  }

  public UdpSyslogFlowFactory(NettyConsumer consumer) {
    this();
    this.consumer = consumer;
  }

  @Override
  protected void initChannel(Channel ch) throws Exception {
    ChannelPipeline channelPipeline = ch.pipeline();
    channelPipeline.addLast("encoder-SD", new StringEncoder(StandardCharsets.UTF_8));
    channelPipeline.addLast("decoder-DELIM",
        new DelimiterBasedFrameDecoder(maxLineSize, true, Delimiters.lineDelimiter()));
    channelPipeline.addLast("decoder-SD", new StringDecoder(StandardCharsets.UTF_8));
    channelPipeline.addLast("handler", new ServerChannelHandler(consumer));
  }

  @Override
  public ServerInitializerFactory createPipelineFactory(NettyConsumer consumer) {
    return new UdpSyslogFlowFactory(consumer);
  }

}

看起来传入的 udp 消息没有被引用 StringDecoder 处理。

任何人都可以提供使用 Camel 对所有传入消息进行简单文本解码的 UDP 服务器的完整示例?

【问题讨论】:

  • 嗨@CHEM_Eugene,我现在面临同样的问题,你有没有让Apache Camel 为系统日志消息工作?您能分享您对此的见解吗?谢谢!

标签: spring-boot apache-camel netty


【解决方案1】:

与其自己构建 syslog-consumer 和解码器,不如查看Camel syslog DataFormat

在链接的文档页面上,您可以找到带有 nettymina 组件的 syslog-consumer 示例。

【讨论】:

    猜你喜欢
    • 2014-09-02
    • 1970-01-01
    • 1970-01-01
    • 2016-06-15
    • 1970-01-01
    • 2013-08-26
    • 1970-01-01
    • 1970-01-01
    • 2015-08-04
    相关资源
    最近更新 更多