简体   繁体   中英

convert apache camel config to spring java config

we are in the process of converting current spring project into spring boot and at the same time converting all spring beans from xml to java config based.

i am stuck converting camel xml configuration into java based config.

currently we are specified camel config , routes and endpoints , one example as below

    <camel:camelContext id="camelClient">
        <camel:template id="camelTemplate"/>
    </camel:camelContext>


        <template id="camelTemplate"/>

here are couple of endpoints

        <endpoint id="archiveUserQueue"
                  uri="swiftmq:${hk.jms.archive.queue.name}?concurrentConsumers=${hk.jms.archive.queue.consumers}"/>

        <endpoint id="directSmsNotification" uri="direct:sendSMS"/>

one of the routes defined

        <route>
            <from ref="directSmsNotification"/>
            <to uri="bean:messengerService?method=sendSmsMessage"/>
        </route>

in java code we access the end point as below

smsEndpoint = _camelContext.getEndpoint("directSmsNotification");

how can we convert the camel config from xml to java based config.

i have followed instructions specified at http://camel.apache.org/spring-java-config.html but it was too hard to understand as i am not familiar with Camel.

You can mix and match Spring Java config with Apache Camel XML config. I question why you're doing this conversion in the first place.

That said, if you look at the camel docs you'll see there's an example for working with RouteBuilder .

You could also look at the sample spring-boot application . Here's a modified RouteBuilder from that example:

@Component
public class MySpringBootRouter extends RouteBuilder {

    @Override
    public void configure() {

        Context context = getContext();
        MyEndpoint ep = context.getEndpoint("someURI", MyEndpoint.class);

        from(ep)
            .transform().simple("ref:myBean")
            .to("log:out");
    }
}

Update : I modified the snippet to show getting an Endpoint directly. You can get more info in the Camel docs . I'm not sure how common this approach is. Back when I was using Camel regularly the endpoints were configured declaratively through their URI values. I don't think I ever explicitly defined an endpoint in my Camel XML or Java code. I'm sure there are use cases for it but it might be simpler for you to configure just by URI.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM