Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the advantages and disadvantages of defining Camel routes in spring xml?

Currently I try to get deeper into Apache Camel. As you know there are at least two ways to describe the routes: the Java DSL and the XML-configuration.

The developers of Camel recommend to use the Java DSL because i.e. it has the benefit that it better integrates into the IDE. Another benefit is, that you can enrich the Java DSL with your own code without writing complex class structures. This seems necessary if XML-configuration is taken.

What do you think are the advantages and disadvantages of routes defined in an xml-file? When to use xml-files for definition of routes and when to use Java DSL?

like image 287
martin Avatar asked Aug 15 '11 12:08

martin


3 Answers

It depends on your requirements a bit, but in almost every case, I prefer the Java DSL for the following reasons:

  • more efficient and flexible than XML
  • less flipping between XML/Java files
  • easier to visualize, manage, maintain, debug, test (via mock, etc.)
  • support for inline Processors
  • better integration with IDE (code completion and validation)
  • cleaner, easier to follow examples
like image 97
Ben ODay Avatar answered Sep 30 '22 04:09

Ben ODay


If you use the Java DSL you can leverage your IDE's refactoring tools and compile time checks.

On the other hand if you use xml files you can externalize the entire camel routing and re-route stuff without redeploying the application.

like image 33
Kees de Kooter Avatar answered Sep 30 '22 02:09

Kees de Kooter


If you start using spring you will most likely come to a point where you need to implement an Processor or something else. You will need custom code at some point. After this you have a mix of java and xml in your code - maintenance horror.

beside this java is:

  • type safe
  • compiled

to get the most out of it i would also suggest to minimize configuration of endpoints with strings. So instead of creating and configuring endpoints this way:

from("file:/someFolder?delete=true")

i suggest do create/configure the endpoint separately:

Endpoint fileEndpoint= context.getEndpoint("file:" + folder.getPath(), FileEndpoint.class);
fileEndpoint.setDelete(true);

This is less error prone than fiddling around strings.

like image 42
dermoritz Avatar answered Sep 30 '22 03:09

dermoritz