CHEM_Eugene
CHEM_Eugene

Reputation: 438

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?

Upvotes: 3

Views: 957

Answers (1)

burki
burki

Reputation: 7005

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.

Upvotes: 4

Related Questions