简体   繁体   中英

Dynamic object parameter in camel consumer endpoint url

I'm using camel with spring. One of our routes should send a TCP message to a dynamically selected endpoint. As the endpoint is just a string, I know I can use

.toD("netty4://...")

but the problem is with setting ssl parameters.

Netty component defines this as route url parameter so it looks like this:

.toD("netty4://...?sslContextParameters=mySslContextParameters");

and to make this work I have a bean:

@Bean
public SslContextParameters mySslContextParameters() {
    ...
    return sslContextParameters();
}

This binds it to this single bean instance but what I need, is a dynamically configured bean so that I may set different parameters of the SSL based on some data I get from the producer.

What I would like is something like this (I know this is not proper camel syntax), when I could invoke a factory method and pass some parameters to it:

.toD("netty://...?sslContextParameters=${bean('mySslContestParameters(${exchange.param1}, ${exchange.param2}')}");

您可以根据此骆驼常见问题解答使用收件人列表EIP。

You can use the recipient list EIP per this camel FAQ.

Thx Steve, it was a good advice.

I had a similiar question, I used your advice and it's work!

In my camel-context.xml, I define two sslContextParameters

...
<camel:sslContextParameters id="firstSsl">
    <camel:keyManagers keyPassword="changeit">
        <camel:keyStore resource="/test/client.keystore.jks" password="changeit" />
    </camel:keyManagers>
    <camel:trustManagers>
            <camel:keyStore resource="/test/client.truststore.jks" password="changeit" />
    </camel:trustManagers>
</camel:sslContextParameters>
<camel:sslContextParameters id="secondSsl">
    <camel:keyManagers keyPassword="otherpassword">
        <camel:keyStore resource="/test/other-keystore.jks" password="otherpassword" />
    </camel:keyManagers>
    <camel:trustManagers>
        <camel:keyStore resource="/test/other-truststore.jks" password="otherpassword" />
    </camel:trustManagers>
</camel:sslContextParameters>
...

In my routeBuilder

.setHeader("sslContext", constant("firstSsl"))
//or
.setHeader("sslContext", constant("secondSsl"))
...
.recipientList(simple("https4://override/?bridgeEndpoint=false&sslContextParametersRef=${headers.sslContext}"))

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