You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by redpower1989 <re...@hotmail.com> on 2016/09/19 11:19:36 UTC
Database route shutdown
Hello i am trying to stop the route when the application detects that there
is no database connection. First in camelContect
<onException>
<exception>org.springframework.jdbc.CannotGetJdbcConnectionException</exception>
<to uri="direct:stopRoute" />
</onException>
<route id="stopRoute" routePolicyRef="StopRoutePolicy">
<from uri="direct:stopRoute" />
<log message="${id}: Database connection lost, message has been stopped"
loggingLevel="DEBUG" />
<stop />
</route>
Inside my stopRoutePolicy bean:
public void onExchangeBegin(Route route, Exchange exchange) {
CamelContext context = exchange.getContext();
String routeId = exchange.getFromRouteId();
if (context.getRouteStatus(routeId) != null &&
context.getRouteStatus(routeId).isStarted()) {
try {
exchange.getContext().getInflightRepository().remove(exchange);
LOG.info("Stopping route: {}", routeId);
context.stopRoute(routeId);
} catch (Exception exception) {
getExceptionHandler().handleException(exception);
}
}
}
and i am getting this log messages
Exchange[ID-FC8BG42-49403-1474282224072-1-7]
19 Sep 2016 11:52:34 StopRoutePolicyDatabase
INFO Stopping route: routeId
19 Sep 2016 11:52:34 DefaultShutdownStrategy
INFO Starting to graceful shutdown 1 routes (timeout 10 seconds)
19 Sep 2016 11:52:34 [ext) thread #19 - ShutdownTask DefaultShutdownStrategy
INFO Waiting as there are still 1 inflight and pending exchanges to
comple
te, timeout in 10 seconds. Inflights per route: routeId = 1
19 Sep 2016 11:52:35 [ext) thread #19 - ShutdownTask DefaultShutdownStrategy
INFO Waiting as there are still 1 inflight and pending exchanges to
comple
te, timeout in 9 seconds. Inflights per route: routeId = 1
...
19 Sep 2016 11:52:44 DefaultShutdownStrategy
WARN Timeout occurred during graceful shutdown. Forcing the routes to
be s
hutdown now. Notice: some resources may still be running as graceful
shutdown di
d not complete successfully.
19 Sep 2016 11:52:44 [ext) thread #19 - ShutdownTask]
DefaultShutdownStrategy
WARN Interrupted while waiting during graceful shutdown, will force
shutdo
wn now.
19 Sep 2016 11:52:44 [ext) thread #19 - ShutdownTask]
DefaultShutdownStrategy
INFO Route: routeId shutdown complete, was consuming from: En
dpoint
My question is as i use :
exchange.getContext().getInflightRepository().remove(exchange);
Still when i am trying to stop the route why am i getting messages that
there is inflight and pending exchanges to complete? How can i avoid this
situation? Also when i use
context.getShutdownStrategy().setTimeout(30);
it does not seems to change the timeout.
--
View this message in context: http://camel.465427.n5.nabble.com/Database-route-shutdown-tp5787725.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Database route shutdown
Posted by redpower1989 <re...@hotmail.com>.
Hello,
Thanks for the response. According to the FAQ in order to stop a route it is
better to do it inside a different thread. In my case that worked fine. Now
i am trying when the database is available to start egain the stopped route.
If i want to start a route do i have to do it again from a different thead
or should i implement the loging inside the stopping thread?
Thanks
--
View this message in context: http://camel.465427.n5.nabble.com/Database-route-shutdown-tp5787725p5787860.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Database route shutdown
Posted by Claus Ibsen <cl...@gmail.com>.
Hi
See this FAQ
http://camel.apache.org/how-can-i-stop-a-route-from-a-route.html
On Mon, Sep 19, 2016 at 1:19 PM, redpower1989 <re...@hotmail.com> wrote:
> Hello i am trying to stop the route when the application detects that there
> is no database connection. First in camelContect
>
> <onException>
>
> <exception>org.springframework.jdbc.CannotGetJdbcConnectionException</exception>
> <to uri="direct:stopRoute" />
> </onException>
>
>
> <route id="stopRoute" routePolicyRef="StopRoutePolicy">
> <from uri="direct:stopRoute" />
> <log message="${id}: Database connection lost, message has been stopped"
> loggingLevel="DEBUG" />
> <stop />
> </route>
>
> Inside my stopRoutePolicy bean:
>
> public void onExchangeBegin(Route route, Exchange exchange) {
> CamelContext context = exchange.getContext();
> String routeId = exchange.getFromRouteId();
> if (context.getRouteStatus(routeId) != null &&
> context.getRouteStatus(routeId).isStarted()) {
> try {
> exchange.getContext().getInflightRepository().remove(exchange);
> LOG.info("Stopping route: {}", routeId);
> context.stopRoute(routeId);
> } catch (Exception exception) {
> getExceptionHandler().handleException(exception);
> }
> }
> }
> and i am getting this log messages
>
> Exchange[ID-FC8BG42-49403-1474282224072-1-7]
> 19 Sep 2016 11:52:34 StopRoutePolicyDatabase
> INFO Stopping route: routeId
> 19 Sep 2016 11:52:34 DefaultShutdownStrategy
> INFO Starting to graceful shutdown 1 routes (timeout 10 seconds)
> 19 Sep 2016 11:52:34 [ext) thread #19 - ShutdownTask DefaultShutdownStrategy
> INFO Waiting as there are still 1 inflight and pending exchanges to
> comple
> te, timeout in 10 seconds. Inflights per route: routeId = 1
> 19 Sep 2016 11:52:35 [ext) thread #19 - ShutdownTask DefaultShutdownStrategy
> INFO Waiting as there are still 1 inflight and pending exchanges to
> comple
> te, timeout in 9 seconds. Inflights per route: routeId = 1
> ...
>
> 19 Sep 2016 11:52:44 DefaultShutdownStrategy
> WARN Timeout occurred during graceful shutdown. Forcing the routes to
> be s
> hutdown now. Notice: some resources may still be running as graceful
> shutdown di
> d not complete successfully.
> 19 Sep 2016 11:52:44 [ext) thread #19 - ShutdownTask]
> DefaultShutdownStrategy
> WARN Interrupted while waiting during graceful shutdown, will force
> shutdo
> wn now.
> 19 Sep 2016 11:52:44 [ext) thread #19 - ShutdownTask]
> DefaultShutdownStrategy
> INFO Route: routeId shutdown complete, was consuming from: En
> dpoint
>
> My question is as i use :
> exchange.getContext().getInflightRepository().remove(exchange);
>
> Still when i am trying to stop the route why am i getting messages that
> there is inflight and pending exchanges to complete? How can i avoid this
> situation? Also when i use
> context.getShutdownStrategy().setTimeout(30);
> it does not seems to change the timeout.
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Database-route-shutdown-tp5787725.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
--
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2