Tuesday, August 20, 2013

Taste of Apache Camel: Part I - Property Placeholder

I started learning Apache Camel about a year ago. All routes are running in Red Hat JBoss FUSE, but about that some other time.
All routes are written in Java DSL and Blueprint with help of Maven.
I will show how to use Property Placeholder in blueprint.xml to set some properties which will be used in route. The route will be simple. The route will listen on some URL on port, that is set in blueprint.xml and returns some answer.
First we must set pom.xml:
Next step is blueprint.xml. It must be in folder resources/OSGI-INF/blueprint. Here are two properties. First one is port on which this service will be accessible. Second one is answer of this service. What are all other things I will try to explain when looking at FUSE Fabric.
Finally the source code. Every class that has route defined as Java DSL, must extend org.apache.camel.builder.RouteBuilder. And that class must implement configure() method. To run this route in shell, main method must create org.apache.camel.main.Main object. When route is started, it should be accessible on url http://localhost:2013/ppexample/{yout text}.
If this works, you should notice that port is set to what was value in main method and not in blueprint.xml. If you omit setters in main method, values from blueprint.xml will be used.

My posts on APache Camel:
 - Part I - Property Placeholder
 - Part II - Using Beans
 - Part III - More on using Beans  - Part IV - Solr
 - Part V - Marshalling and Unmarshalling

No comments:

Post a Comment