问题
Is is possible to log simple text in Camel as follows
<route>
<from uri="direct:cxlrefdata"/>
<to uri="log:'Hello World'" />
</route>
I want to log this message, 'Hello World' in log, but all the examples which I find in Apache Camel site are for logging route messages.
e.g
<route>
<from uri="direct:t1"/>
<to uri="log:output?showAll=true" />
</route>
I want something simple which can log test messages.
回答1:
Yes see the log eip http://camel.apache.org/logeip.html
This allows you to log human readable messages to the log. You could have spotted it, by the green tip box on the log component page: http://camel.apache.org/log
回答2:
TL;DR
DO NOT forget about
camel.springboot.main-run-controller=true
inapplication.properties
from("timer://scheduler?fixedRate=true&period=5s") .log("Hello World!");
Let me provide you the simplest example written in Java DSL. I will use the Spring Boot Camel starter to setup the simplest runnable piece of code. This example will help you to log the message Hello World!
to your console every 5 seconds according to quartz2
component cron
expression.
Documentation to look through:
- Spring Boot & Apache Camel - https://camel.apache.org/spring-boot
- Camel's Quartz2 component - http://camel.apache.org/quartz2.html
Here is your simplest Spring Boot demo application:
package com.lordnighton.camel.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
Here is the simplest route that logs the message HelloWorld!
into console every 5 seconds:
package com.lordnighton.camel.demo.routes;
import org.apache.camel.builder.RouteBuilder;
import org.springframework.stereotype.Component;
@Component
public class LogMessageRoute extends RouteBuilder {
@Override
public void configure() throws Exception {
from("quartz2://logMessageGroup/logMessageTimer?cron=0/5+*+*+*+*+?")
.log("Hello World!");
}
}
来源:https://stackoverflow.com/questions/15922822/logging-simple-text-in-apache-camel-logs