You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Michael Esmann <mi...@hotmail.com> on 2017/12/21 10:27:22 UTC
Set shutdown timeout with blueprint
Hi,
I am using Apache Camel 2.17.3 and Karaf 4.0.6.
I would like to change the default shutdown startegy timeout with blueprint.
It works if I do it like this, with a hardcoded timeout value:
<bean id="MyShutdownStrategy"
class="org.apache.camel.impl.DefaultShutdownStrategy">
<property name="timeout" value="100"/>
</bean>
But I would like the timeout to be configurable with a property like this:
<bean id="MyShutdownStrategy"
class="org.apache.camel.impl.DefaultShutdownStrategy">
<property name="timeout" value="${camel.shutdownstrategy.timeout}"/>
</bean>
If I do it like this I get an error when deploying:
"Unable to start blueprint container for bundle MyBundle
org.osgi.service.blueprint.container.ComponentDefinitionException: Name
MyShutdownStrategy is already instanciated as null and cannot be removed."
Even if I resolve this problem then I could be afraid that I will get
another error because "timeout" property is a long value(?).
Any suggestions about how I can solve these problems?
Thanks,
Michael
Re: Set shutdown timeout with blueprint
Posted by Quinn Stevenson <qu...@pronoia-solutions.com>.
I just tested a simple route in Karaf 4.0.10 and Camel 2.17.7, and it seems to work. (I apologize for the messy route - it’s just one I had laying around and I’m not actually sure where I got it). Given the route I used, I can create a my.camel.bp.cfg file in the $KARAF_HOME/etc directory and change the value of the timeout (the route will restart and the bean will show the new value is in use.
The Blueprint I used looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<blueprint
xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0
http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0
http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.1.0.xsd">
<property-placeholder xmlns="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
persistent-id="my.camel.bp"
update-strategy="reload">
<default-properties>
<property name="my.label" value="OK" />
<property name="my.logger" value="BP-TEST" />
<property name="my.flag" value="true" />
<property name="my.path" value="BLUEPRINT" />
<property name="my.shutdownstrategy.timeout" value="1000" />
</default-properties>
</property-placeholder>
<bean id="shutdown-stratagy" class="org.apache.camel.impl.DefaultShutdownStrategy" >
<property name="timeout" value="${my.shutdownstrategy.timeout}" />
</bean>
<bean id="context-info-logger" class="com.pronoia.scratch.camel.ContextInfoProcessor" />
<camelContext
id="MY-CONTEXT"
xmlns="http://camel.apache.org/schema/blueprint"
xsi:schemaLocation="http://camel.apache.org/schema/blueprint
http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">
<route id="MY-ROUTE-1">
<from uri="timer://test-1"/>
<process ref="context-info-logger" />
<transform>
<simple>${properties:my.label}:${body}</simple>
</transform>
<log
logName="{{my.logger}}"
message="Result body=${body}"/>
</route>
<route id="MY-ROUTE-2">
<from uri="file:C:/TMP/TESTS/{{my.path}}?autoCreate={{my.flag}}"/>
<to uri="direct:test1"/>
</route>
</camelContext>
</blueprint>
And the context-info-logger bean source is:
public class ContextInfoProcessor implements Processor{
Logger log = LoggerFactory.getLogger(this.getClass());
@Override
public void process(Exchange exchange) throws Exception {
String units = "UNKNOWN";
switch (exchange.getContext().getShutdownStrategy().getTimeUnit()) {
case NANOSECONDS:
units = "NANOSECONDS";
break;
case MICROSECONDS:
units = "MICROSECONDS";
break;
case MILLISECONDS:
units = "MILLISECONDS";
break;
case SECONDS:
units = "SECONDS";
break;
case MINUTES:
units = "MINUTES";
break;
case HOURS:
units = "HOURS";
break;
case DAYS:
units = "DAYS";
}
log.info("***** Shutdown Timeout = {} {} *****", exchange.getContext().getShutdownStrategy().getTimeout(), units);
}
}
Can you share the full XML you are using?
Quinn Stevenson
quinn@pronoia-solutions.com
(801) 244-7758
> On Dec 21, 2017, at 3:27 AM, Michael Esmann <mi...@hotmail.com> wrote:
>
> camel.shutdownstrategy.timeout