Hi You are closing spring from the same thread that Camel is using to route that message so it will likely block and cause the message to not finish its remainder work, eg such as unregister from inflight and so on.
So use a new thread to call the spring close, eg new Thread() ... start() so you signal spring to stop from another thread, and at the same time the onExchangeDone can continue and finish the last bits it needs so the shutdown is clean On Tue, Aug 13, 2019 at 2:03 AM Dmitri Van De Kerckhove <[email protected]> wrote: > > We are already running Dockerised Apache Camel/Spring Boot containers and > have been looking at deploying them inside Kubernetes, and using the > Kubernetes Cron Job to create a Jobs on a time-based schedule. > > Since the scheduling will happen "outside" Camel for our (ETL) Camel route I > have replaced the scheduled interval with a timer that fires just once: > > > from("timer://foo?repeatCount=1") > .routePolicy(myPolicy) > .routeId("timer in action") > .to("mock:foo"); > > > Because the Kubernetes Job needs to complete, we need not just stop the > route, but the SpringBoot application context. For that purpose we define a > Policy - mostly noop - except for the OnExchangeComplete method, which closes > the autowired appContext: > > > public void onExchangeDone(Route route, Exchange exchange) { > appContext.close(); > } > > > That works, but I still get a warning before the Spring Container shuts down: > > > o.a.c.i.DefaultInflightRepository | Shutting down while there are still 1 > inflight exchanges. > Spring Container is destroyed! > > > If I put the extra logging below in, it confirms there is 1 Exchange for the > "timer in action" route > > > > camelContext.getInflightRepository().browse().iterator().next().getFromRouteId()); > camelContext.getInflightRepository().browse().size()); > > > My question is: given this is fire-once timer route, and the Exchange is done > being routed, why would there still be 1 inflight exchange? And if above is > not correct approach, what would be a correct way/time to close the spring > context? > > > This e-mail may contain information which is confidential, subject to legal > privilege and /or protected by copyright. If you are not the intended > recipient (or have received this e-mail in error) please notify the sender > immediately and destroy all copies of this email. -- Claus Ibsen ----------------- http://davsclaus.com @davsclaus Camel in Action 2: https://www.manning.com/ibsen2
