tuk
tuk

Reputation: 6872

Overriding default properties in camel http4 component via blueprint

I want to change maxTotalConnections and connectionsPerRoute in camel http4 component via blueprint.

Can some one let me know is it possible to do this or I have to send this as URI option?

I am on camel 2.16.3

Upvotes: 1

Views: 1628

Answers (1)

AndyN
AndyN

Reputation: 2105

Camel does let you setup routes using OSGi Blueprint. It also lets you use Property Placeholders with Blueprint values. But you would need to place those values in the URI.

So, you could use something like:

<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
    <cm:property-placeholder persistent-id="my-placeholders" update-strategy="reload">
      <cm:default-properties>
          <cm:property name="maxTotalConnections" value="200"/>
          <cm:property name="connectionsPerRoute" value="20"/>
      </cm:default-properties>
    </cm:property-placeholder>

    <camelContext xmlns="http://camel.apache.org/schema/blueprint">
        <route>
            <from uri="timer:test" />
            <to uri="http4:localhost:80/resource?maxTotalConnections={{maxTotalConnections}}&amp;connectionsPerRoute={{connectionsPerRoute}}" />
        </route>
    </camelContext>

</blueprint>

Component options are set when the first route is created using that component. Looking in the code, maxTotalConnections and connectionsPerRoute are set when creating a new endpoint like so:

HttpClientConnectionManager localConnectionManager = clientConnectionManager;
if (localConnectionManager == null) {
    // need to check the parameters of maxTotalConnections and connectionsPerRoute
    int maxTotalConnections = getAndRemoveParameter(parameters, "maxTotalConnections", int.class, 0);
    int connectionsPerRoute = getAndRemoveParameter(parameters, "connectionsPerRoute", int.class, 0);
    localConnectionManager = createConnectionManager(createConnectionRegistry(x509HostnameVerifier, sslContextParameters), maxTotalConnections, connectionsPerRoute);
}

Once the first route is setup, the clientConnectionManager is set. For any other routes setup after the first one, as the clientConnectionManager is tied to the single instance of the Http4 Component, it looks like those options are ignored. I would use the same component options on all routes.

You can instantiate new HTTP4 components by creating new beans and giving them an id. You may be able to use this to create multiple http4 components with different component options.

<bean id="http4-foo" class="org.apache.camel.component.http4.HttpComponent"/>
<bean id="http4-bar" class="org.apache.camel.component.http4.HttpComponent"/>

Then just use those IDs when setting up the endpoints.

<to uri="http4-foo:localhost:80/resource?maxTotalConnections=300"/>

Upvotes: 1

Related Questions