This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel-spring-boot-examples.git
commit d8729f5c3c982ddf66cf2a9c0d1b863daef49021 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Mon May 25 12:07:51 2020 +0200 Polished example --- .../src/main/java/sample/camel/MyBean.java | 6 ++++-- .../src/main/java/sample/camel/MyCamelRouter.java | 15 ++++++++++----- .../src/main/resources/application.properties | 4 ++-- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/camel-example-spring-boot/src/main/java/sample/camel/MyBean.java b/camel-example-spring-boot/src/main/java/sample/camel/MyBean.java index 9651eaa..45b9aa8 100644 --- a/camel-example-spring-boot/src/main/java/sample/camel/MyBean.java +++ b/camel-example-spring-boot/src/main/java/sample/camel/MyBean.java @@ -28,11 +28,13 @@ import org.springframework.stereotype.Component; @Component("myBean") public class MyBean { + private int counter; + @Value("${greeting}") private String say; - public String saySomething() { - return say; + public String saySomething(String body) { + return String.format("%s I am invoked %d times", say, ++counter); } } diff --git a/camel-example-spring-boot/src/main/java/sample/camel/MyCamelRouter.java b/camel-example-spring-boot/src/main/java/sample/camel/MyCamelRouter.java index bc8dc22..8321887 100644 --- a/camel-example-spring-boot/src/main/java/sample/camel/MyCamelRouter.java +++ b/camel-example-spring-boot/src/main/java/sample/camel/MyCamelRouter.java @@ -17,6 +17,7 @@ package sample.camel; import org.apache.camel.builder.RouteBuilder; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; /** @@ -27,13 +28,17 @@ import org.springframework.stereotype.Component; @Component public class MyCamelRouter extends RouteBuilder { + // we can use spring dependency injection + @Autowired + MyBean myBean; + @Override public void configure() throws Exception { - from("timer:hello?period={{timer.period}}").routeId("hello") - .transform().method("myBean", "saySomething") - .filter(simple("${body} contains 'foo'")) - .to("log:foo") - .end() + // start from a timer + from("timer:hello?period={{myPeriod}}").routeId("hello") + // and call the bean + .bean(myBean, "saySomething") + // and print it to system out via stream component .to("stream:out"); } diff --git a/camel-example-spring-boot/src/main/resources/application.properties b/camel-example-spring-boot/src/main/resources/application.properties index 7333594..7ec89a3 100644 --- a/camel-example-spring-boot/src/main/resources/application.properties +++ b/camel-example-spring-boot/src/main/resources/application.properties @@ -21,8 +21,8 @@ camel.springboot.name = MyCamel # what to say greeting = Hello World -# how often to trigger the timer -timer.period = 2000 +# how often to trigger the timer (millis) +myPeriod = 2000 # to watch bean introspection using java reflection usage # camel.springboot.bean-introspection-logging-level=INFO