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?
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
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.
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.
精彩评论