This example shows how to work with a simple Apache Camel application using Spring Boot with declarative content validation enabled.
The example generates messages using timer trigger, writes them to standard output. The output type is declared as greeting
, which has corresponding validator defined.
The Camel route is located in the SampleCamelRouter
class. In this class the route
starts from a timer, that triggers every 2nd second and calls a Spring Bean SampleBean
which returns a message, that is routed to a stream endpoint which writes to standard output.
The output type is declared as greeting
, and the validator GreetingValidator
is registered
to be triggered for greeting
output message right after the routing.
Apache Camel provides 200+ components which you can use to integrate and route messages between many systems and data formats. To use any of these Camel components, add the component as a dependency to your project.
You can run this example using
mvn spring-boot:run
You can run this example with validation failure using
mvn spring-boot:run -Dspring-boot.run.arguments=Hello_Mars
Create your own project
oc new-project csb-example-validator
So you can deploy and run with the command
mvn clean package -Popenshift -Dgreeting=Hello_World -DskipTests
You can run this example with validation failure using
mvn clean package -Popenshift -Dgreeting=Hello_Mars -DskipTests
Given that by default terminationGracePeriodSeconds is 30 seconds and camel.main.shutdown-timeout is 45, this example shows how to configure both of them so that the pod is not killed before the shutdown-timeout:
in src/main/jkube/deployment.yml we can configure the Pod graceful termination period
spec: template: spec: containers: # ... terminationGracePeriodSeconds: 60 # default is 30
On the application side we need to add some properties to set and verify the desired camel route shutdown using the camel DefaultShutdownStrategy feature:
src/main/resources/application.properties
# increase graceful shutdown timeout to 60 seconds (default is 45) camel.main.shutdown-timeout = 60 # (default is 45) camel.springboot.shutdown-timeout = 60
# monitoring the DefaultShutdownStrategy behaviour logging.level.org.apache.camel.impl.engine.DefaultShutdownStrategy = DEBUG
If you hit any problem using Camel or have some feedback, then please let us know.
We also love contributors, so get involved :-)
The Camel riders!