On Wed, Feb 4, 2015 at 11:17 AM, Jan Matèrne (jhm) <apa...@materne.de> wrote: > The URI is just a string. > Why not extract your "builder" into a simple utility method > > public class EndpointUtils { > public static String rabbitEndpoint(String scheme, String host, String > host) { > ... > } > } > > With SpringDSL property placeholder come into mind ... > > > Having special builders sound also fine, but a lot of work as it requires one > builder per endpoint ... >
Yeah although Camel 2.15 offers the ability for us to generate the source code for those builders, as each component has information about each of their options. Certainly having to hand craft those for 170+ components is way to much and also keep them up to date, so I like the source code generation approach. But on the other hand, many people use the Camel components using configuration and uris only, without having to add those JARs and use their java types in their own apps. eg you can use the FTP component without even have it on the classpath at development time (eg no import of its java classes), of course for runtime you would need it. > > Jan > > >> -----Ursprüngliche Nachricht----- >> Von: Nathan Jones [mailto:nat...@ncjones.com] >> Gesendet: Mittwoch, 4. Februar 2015 10:55 >> An: users@camel.apache.org >> Betreff: Patterns for DRY Camel endpoints >> >> Is there a standard pattern for defining Camel endpoints so that >> commonly used endpoint settings do not need to be repeated in every >> endpoint definition? For example, every RabbitMQ endpoint I declare >> always repeats the same connection settings like the following: >> >> >> rabbitmq://{{rabbitmq.host}}:{{rabbitmq.port}}/exchange?username=... >> >> I'm thinking of having an (immutable) endpoint URL builder that can be >> reused by all route builders. Then I would only need to set the common >> connection settings once (say, in my Spring configuration): >> >> @Bean >> UrlBuilder rmqEndpointUrlBuilder() { >> return new UrlBuilder() >> .setScheme("rabbitmq") >> .setHost("{{rabbitmq.host}}") >> .setPort("{{rabbitmq.port}}"); >> } >> >> >> That URL builder would be injected into my Camel route builder and can >> be used like so: >> >> from(rmqEndpointUrlBuilder.setPath("/exchange").toString()) >> >> Does this sound reasonable? Is there a simpler way to achieve this? >> >> Taking the endpoint builder idea further may be interesting. If there >> were endpoint builders specific to each component type then it would be >> a lot easier to define endpoint URL parameters. Has this sort of thing >> been considered before? >> >> - Nathan > -- Claus Ibsen ----------------- Red Hat, Inc. Email: cib...@redhat.com Twitter: davsclaus Blog: http://davsclaus.com Author of Camel in Action: http://www.manning.com/ibsen hawtio: http://hawt.io/ fabric8: http://fabric8.io/