Giovanni Bricconi

My site on WordPress.com

Traveling with Camel in the Java-verse

leave a comment »

Sometimes I feel like Alice in Wonderland, you never know what is going to happen and which strange beast I am going to face.

Today’s beast is Camel: I have nothing against it, I barely know what it is, but I have just seen another episode of “I am a bored developer, let me try a new framework. One day it will be useful”

So in Camel you have a RouteBuilder, inside the route a message is delivered to all the Handler registered. There is an xml configuration file where you can define beans with spring

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:camel="http://camel.apache.org/schema/spring"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans classpath:/org/springframework/beans/factory/xml/spring-beans-4.3.xsd
       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">

  <!-- camelContext is the Camel runtime, where we can host Camel routes -->
  <camel:camelContext xmlns="http://camel.apache.org/schema/spring">
    <camel:routeBuilder ref="routerBuilder"/>    
  </camel:camelContext>
  
  <bean id="routerBuilder" class="MyRouteBuilder"/>
  <bean id="A" class="AClass"/>
  <bean id="B" class="BClass"/>
</beans>

So this create a context, 3 beans and the first one is the route builder. Inside MyRouteBuilder you can

		from("timer://simpleTimer?period={{timer}}")
		.to("bean:A")
		.to("bean:B");

so you can tell that the source event to process is just a timer that is expiring, then the 2 handlers have to be invoked.

Quite overkill to use a framework like Camel to just do periodically a couple of calls. At least this time the beast I faced was not so difficult to understand.

Many thanks to https://www.baeldung.com/apache-camel-intro that always provide good short articles to understand quickly what is going on.

Written by Giovanni

March 29, 2022 at 11:53 am

Posted in Varie

Leave a comment