Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache Camel based Udp server

I'm trying to use Apache Camel to create udp server which consumes syslog messages.

There are no examples how to do it correctly.

I wrote following route, which use custom 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");
}

}

Code of factory:

@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);
  }

}

It looks like incoming udp messages don't processed by references StringDecoder.

Anybody can provide full example of UDP Server with Camel which use simple text decoding of all incoming messages?

like image 822
CHEM_Eugene Avatar asked Feb 14 '26 01:02

CHEM_Eugene


1 Answers

Instead of building the syslog-consumer and decoder by yourself, have a look at the Camel syslog DataFormat.

On the linked documentation page you can find syslog-consumer examples with netty and mina components.

like image 148
burki Avatar answered Feb 16 '26 12:02

burki



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!