Apache camel syslog元件透過netty接收連線,並將訊息轉為SyslogMessage物件,它支援RFC3164與RFC5424的訊息格式。目前測試後,可以正常收到RHEL、Ubuntu與SLES所送出的syslog;而vmware esxi的日期格式是iso8601,所以無法正常轉為SyslogMessage。
使用這個解法的好處是可以省去自己實作接syslog的listener與parse message的部分。
java
@Test public void test() throws Exception { CamelContext context = new DefaultCamelContext(); try { context.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { String uri = "netty:udp://0.0.0.0:514?sync=false&allowDefaultCodec=false"; from(uri). unmarshal("syslog") .process(new Processor() { @Override public void process(Exchange aExchangeData) throws Exception { if (!(aExchangeData.getIn().getBody() instanceof SyslogMessage)) return; SyslogMessage msg = (SyslogMessage)aExchangeData.getIn().getBody(); System.out.println(msg); } }); } }); context.start(); System.out.println("Enter"); Scanner s = new Scanner(System.in); s.next(); s.close(); } finally { context.stop(); } }
ivy
<dependency org="org.apache.camel" name="camel-netty" rev="latest.integration"/> <dependency org="io.netty" name="netty" rev="latest.integration"/> <dependency org="org.apache.camel" name="camel-core" rev="latest.integration"/> <dependency org="org.apache.camel" name="camel-syslog" rev="latest.integration"/>
留言
張貼留言