I just started working on a Apache Camel with Spring and CXF rest web service and while going through the current code I am not able to understand the few things.
Normally for apache camel we need to create a
CamelContextand then link it toproducerTemplateand then we add the route to theCamelContextlike below.CamelContext context = new DefaultCamelContext(); ProducerTemplate template = context.createProducerTemplate(); context.addRoutes(new RouteBuilder() {public void configure() { ... }But when I see this in spring application its different, We are creating camel context in XML file with below which will allow spring to search the Spring
ApplicationContextfor route builder instances i.e. Camel pickup anyRouteBuilderinstances which was created by Spring in its scan process.<camel-spring:camelContext id="marriottCamelContext" useMDCLogging="true" xmlns="http://camel.apache.org/schema/spring"> <camel-spring:contextScan /> <template id="xxxTemplateProducer" camelContextId="xxxCamelContext" /> </camel-spring:camelContext>So above is the linking of RouteBuilder with camel context.
Now for the producer Template, as in the application we are just creating the object in
@Serviceclass like below and sending the request toRouteclass@Autowired private ProducerTemplate template; UpsellResponse upsellResponse = template.requestBodyAndHeaders("{{upsell.route}}", upsellRequest, headers, UpsellResponse.class);But I am not able to understand how the template is linked with Camel Context and Route here. And also want to know whether the first point is correct or not.
I also noticed in the Route Class, {{}} are used to in from({{}}) and to({{}}) for the property file variable. Is this any specific rule related to Camel since in spring we use to use ${} for the variable from property file with @PropertySource and @Value
E.g from("{{upsell.route}}").routeId("v2.upsell.Hystrix.Consumer").to("{{upsell.hystrix.consumer.route}}");