Polished example
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 @@
@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 @@
@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 @@
# 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