Hi Giannis, we have a pull request[1] in review that should help with such issues, would you mind taking a look and commenting on it or trying out and confirming that it helps in your case?
As a workaround you could create your own Spring lifecycle bean, it should implement `Lifecycle` and `Phased` as does `SpringCamelContext` in that pull request and in `stop` method perform CamelContext::shutdown. zoran [1] https://github.com/apache/camel/pull/1685 On Thu, May 11, 2017 at 2:44 PM, giannis_k <[email protected]> wrote: > Hello, > > I am using camel 2.18.2 with camel spring boot starter and spring versions: > > <spring.boot-version>1.4.1.RELEASE</spring.boot-version> > <spring.version>4.3.3.RELEASE</spring.version> > > We consume messages from a kafka component and we shutdown the application, > some beans are destroyed before the CamelContext causing messages to be lost > because either e seda component does not exist or the connection to the > database has been closed. Logs from an example: > > > 15:40:48.966 [Thread-3] INFO o.s.c.a.AnnotationConfigApplicationContext - > Closing > org.springframework.context.annotation.AnnotationConfigApplicationContext@4218d6a3: > startup date [Wed May 10 15:40:30 EEST 2017]; root of context hierarchy > 15:40:48.966 [Thread-4] INFO o.a.c.m.MainSupport$HangupInterceptor - > Received hang up - stopping the main instance. > 15:40:48.966 [Thread-4] INFO o.a.camel.spring.SpringCamelContext - Apache > Camel 2.18.2 (CamelContext: camel) is shutting down > 15:40:48.967 [Thread-3] DEBUG o.s.b.f.s.DefaultListableBeanFactory - > Returning cached instance of singleton bean 'sqlSessionFactory' > 15:40:48.967 [Thread-3] DEBUG o.s.b.f.s.DefaultListableBeanFactory - > Returning cached instance of singleton bean 'sqlSessionFactorySecondary' > .... > 15:40:48.968 [Thread-3] DEBUG o.s.b.f.s.DisposableBeanAdapter - Invoking > destroy method 'shutdown' on bean with name 'direct-component' > 15:40:48.968 [Thread-3] DEBUG o.s.b.f.s.DisposableBeanAdapter - Invoking > destroy method 'shutdown' on bean with name 'seda-component' > 15:40:48.973 [Thread-3] DEBUG o.s.b.f.s.DisposableBeanAdapter - Invoking > destroy() on bean with name 'mbeanExporter' > 15:40:48.973 [Thread-3] INFO o.s.j.e.a.AnnotationMBeanExporter - > Unregistering JMX-exposed beans on shutdown > 15:40:48.973 [Thread-4] INFO o.a.c.impl.DefaultShutdownStrategy - Starting > to graceful shutdown 21 routes (timeout 300 seconds) > 15:40:48.974 [Thread-3] INFO o.s.j.e.a.AnnotationMBeanExporter - > Unregistering JMX-exposed beans > 15:40:48.980 [Thread-3] DEBUG o.s.c.a.CommonAnnotationBeanPostProcessor - > Invoking destroy method on bean 'applicationController': private void > org.apache.camel.spring.boot.CamelSpringBootApplicationController.destroy() > 15:40:48.980 [Thread-3] DEBUG o.s.b.f.s.DisposableBeanAdapter - Invoking > destroy() on bean with name 'consumerTemplate' > 15:40:48.980 [Thread-3] DEBUG o.s.b.f.s.DisposableBeanAdapter - Invoking > destroy() on bean with name 'fluentTemplate' > 15:40:48.980 [Thread-3] DEBUG o.s.b.f.s.DisposableBeanAdapter - Invoking > destroy() on bean with name 'template' > 15:40:48.980 [Thread-3] DEBUG o.s.b.f.s.DefaultListableBeanFactory - > Retrieved dependent beans for bean 'camel': [typeConverter, > springTypeConverter, properties, > org.apache.camel.component.kafka.KafkaComponent, constant-language, > org.apache.camel.component.file.FileComponent, > org.apache.camel.component.quartz2.QuartzComponent, > org.apache.camel.component.zookeeper.ZooKeeperComponent, header-language] > 15:40:48.980 [Thread-3] DEBUG o.s.b.f.s.DisposableBeanAdapter - Invoking > destroy() on bean with name 'camel' > 15:40:48.980 [Thread-3] DEBUG o.s.b.f.s.DefaultListableBeanFactory - > Retrieved dependent beans for bean 'ehcache': [cacheManager] > 15:40:48.980 [Thread-3] DEBUG o.s.b.f.s.DefaultListableBeanFactory - > Retrieved dependent beans for bean 'cacheManager': > [org.springframework.cache.interceptor.CacheInterceptor#0] > 15:40:48.980 [Thread-3] DEBUG o.s.b.f.s.DisposableBeanAdapter - Invoking > destroy() on bean with name 'ehcache' > 15:40:48.980 [Thread-3] INFO o.s.c.e.EhCacheManagerFactoryBean - Shutting > down EhCache CacheManager > ... > 15:40:49.017 [Thread-3] DEBUG o.s.b.f.s.DisposableBeanAdapter - Invoking > destroy method 'close' on bean with name 'dataSourceSecondary' > 15:40:49.017 [Thread-3] INFO com.zaxxer.hikari.pool.HikariPool - > HikariPool-2 - Close initiated... > > org.apache.camel.component.seda.SedaConsumerNotAvailableException: No queue > available on endpoint: seda://placed. > at > org.apache.camel.component.seda.SedaProducer.addToQueue(SedaProducer.java:223) > at > org.apache.camel.component.seda.SedaProducer.process(SedaProducer.java:169) > at > org.apache.camel.processor.SendProcessor.process(SendProcessor.java:145) > > > I can see a similar case in here > <http://camel.465427.n5.nabble.com/OnApplicationEvent-not-called-with-CamelAutoConfiguration-td5798802.html> > however the workaround does not work for me. Is there a possible workaround > for this issue? > > Thank you, > Giannis > > > > > -- > View this message in context: > http://camel.465427.n5.nabble.com/Camel-spring-boot-destroys-beans-with-wrong-order-tp5799304.html > Sent from the Camel - Users mailing list archive at Nabble.com. -- Zoran Regvart
