骆驼上下文在应用程序启动后立即启动关闭,没有明显的错误

时间:2019-06-06 08:37:11

标签: spring-boot apache-kafka apache-camel

我的spring-boot应用程序启动了从启用了Kafka的Azure事件中心使用的Camel路由。在该应用程序已启动的消息之后,立即记录以下消息:“ INFO o.a.camel.spring.SpringCamelContext-Apache Camel 2.24.0(CamelContext:camel-1)正在关闭”。

然后,所有的机上交换(如果存在)都被Camel路由成功处理,并且最终该路由被关闭(正常),这也终止了该应用程序。

未显示任何错误消息,似乎没有什么错,除了在应用程序启动后立即自动启动关机。...

知道为什么会这样吗?

我已经尝试过Kafka的超时,但是行为没有改变。

我已将日志记录级别设置为TRACE,但仍然看不到为什么启动关机。

在其他应用程序中,我使用以下库:spring-boot-starter,spring-boot-starter-web,azure-servicebus-spring-boot-starter,camel-kafka,camel-spring-boot-starter,camel-undertow -启动器

这是路线开始的方式:

            from("kafka:dummytopic?brokers=dummy.servicebus.windows.net:9093&topic={{event.hubs.hub.magento}}&groupId={{event.hubs.consumer-group}}"
                    + "&consumersCount=1"
                    + "&autoOffsetReset=latest"
                    + "&saslMechanism=PLAIN"
                    + "&securityProtocol=SASL_SSL"
                    + "&sslProtocol=TLSv1.2"
                    + "&sslEnabledProtocols=TLSv1.2"
                    + "&sslEndpointAlgorithm=HTTPS"
                    + "&saslJaasConfig=" + saslJaasConfig
                    + "&autoCommitEnable=true")
.....

通常,路由应继续运行并轮询kafka事件中心以获取事件(并在事件可用时进行处理)。

相反,它立即启动关机(仍然成功处理所有正在进行的交换)-它只是简单地正常关机。没有错误消息。

感谢您的帮助!

PS:这是跟踪日志的摘录:

15:01:40.867 [main] INFO  c.i.s.n.NotificationMicroserviceApplication - Started NotificationMicroserviceApplication in 10.516 seconds (JVM running for 14.643)
15:01:40.868 [main] TRACE o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'camelContext'
15:01:40.868 [main] TRACE o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'springApplicationAdminRegistrar'
15:01:40.868 [main] DEBUG o.a.camel.spring.SpringCamelContext - onApplicationEvent: org.springframework.boot.context.event.ApplicationStartedEvent[source=org.springframework.boot.SpringApplication@22aefae0]
15:01:40.870 [main] TRACE o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'camelContext'
15:01:40.870 [main] TRACE o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'springApplicationAdminRegistrar'
15:01:40.870 [main] DEBUG o.a.camel.spring.SpringCamelContext - onApplicationEvent: org.springframework.boot.context.event.ApplicationReadyEvent[source=org.springframework.boot.SpringApplication@22aefae0]
15:01:40.872 [Thread-37] DEBUG o.s.c.a.AnnotationConfigApplicationContext - Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@2cd2a21f, started on Thu Jun 06 15:01:31 EEST 2019
15:01:40.873 [Thread-37] TRACE o.s.c.e.PropertySourcesPropertyResolver - Searching for key 'spring.liveBeansView.mbeanDomain' in PropertySource 'configurationProperties'
15:01:40.873 [Thread-37] TRACE o.s.c.e.PropertySourcesPropertyResolver - Searching for key 'spring.liveBeansView.mbeanDomain' in PropertySource 'systemProperties'
15:01:40.873 [Thread-37] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Found key 'spring.liveBeansView.mbeanDomain' in PropertySource 'systemProperties' with value of type String
15:01:40.874 [Thread-37] TRACE o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'camelContext'
15:01:40.874 [Thread-37] TRACE o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'springApplicationAdminRegistrar'
15:01:40.875 [Thread-37] DEBUG o.a.camel.spring.SpringCamelContext - onApplicationEvent: org.springframework.context.event.ContextClosedEvent[source=org.springframework.context.annotation.AnnotationConfigApplicationContext@2cd2a21f, started on Thu Jun 06 15:01:31 EEST 2019]
15:01:40.877 [Thread-37] TRACE o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'camelContext'
15:01:40.877 [Thread-37] TRACE o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'lifecycleProcessor'
15:01:40.879 [Thread-37] DEBUG o.s.c.s.DefaultLifecycleProcessor - Stopping beans in phase 2147483647
15:01:40.879 [Thread-37] TRACE o.s.c.s.DefaultLifecycleProcessor - Stopping bean 'camelContext' of type [org.apache.camel.spring.SpringCamelContext]
15:01:40.879 [Thread-37] INFO  o.a.camel.spring.SpringCamelContext - Apache Camel 2.24.0 (CamelContext: camel-1) is shutting down
15:01:40.879 [Thread-37] TRACE org.apache.camel.util.ServiceHelper - Stopping service org.apache.camel.impl.DefaultRouteController@108b121f
15:01:40.879 [Thread-37] TRACE org.apache.camel.util.ServiceHelper - Shutting down service org.apache.camel.impl.DefaultRouteController@108b121f
15:01:40.879 [Thread-37] TRACE o.a.camel.support.ServiceSupport - Service already stopped
15:01:40.880 [Thread-37] INFO  o.a.c.impl.DefaultShutdownStrategy - Starting to graceful shutdown 1 routes (timeout 300 seconds)
15:01:40.880 [Thread-37] TRACE o.a.c.m.DefaultManagementLifecycleStrategy - Checking whether to register org.apache.camel.util.concurrent.RejectableThreadPoolExecutor@11ee4d34[Running, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0][ShutdownTask] from route: null
15:01:40.880 [Thread-37] DEBUG o.a.c.i.DefaultExecutorServiceManager - Created new ThreadPool for source: org.apache.camel.impl.DefaultShutdownStrategy@58b97c15 with name: ShutdownTask. -> org.apache.camel.util.concurrent.RejectableThreadPoolExecutor@11ee4d34[Running, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0][ShutdownTask]
15:01:41.073 [Thread-37] TRACE o.a.c.u.c.CamelThreadFactory - Created thread[Camel (camel-1) thread #2 - ShutdownTask] -> Thread[Camel (camel-1) thread #2 - ShutdownTask,5,main]
15:01:41.075 [Camel (camel-1) thread #2 - ShutdownTask] DEBUG o.a.c.impl.DefaultShutdownStrategy - There are 1 routes to shutdown
15:01:41.075 [Camel (camel-1) thread #2 - ShutdownTask] TRACE o.a.c.impl.DefaultShutdownStrategy - Shutting down route: routeEventHub with options [Default,CompleteCurrentTaskOnly]

您可以看到它在15:01:40.872开始关闭内容...

4 个答案:

答案 0 :(得分:1)

我遇到了同样的问题,就我而言,解决方案是将下一个依赖项添加到 pom 文件中。

<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>

答案 1 :(得分:0)

没有使应用程序保持活动状态的线程。这就是为什么它立即关闭的原因。

您可能想添加spring-boot-starter-web以使Web容器正在运行,或者在我们的主类中可能有一个阻止关闭的循环。

我会去买网络容器。因此,您还可以在执行器框架中添加一些诊断信息。

答案 2 :(得分:0)

最终,该解决方案成功了:

@Slf4j
@SpringBootApplication
public class NotificationMicroserviceApplication implements CommandLineRunner {

    public static void main(String[] args) {
        SpringApplication.run(NotificationMicroserviceApplication.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
        log.info("You can press Ctrl+C anytime to shutdown application");
        Thread.currentThread().join();
    }
}

答案 3 :(得分:0)

这个和spring版本升级有关。

所描述的问题与不同Maven依赖项之间的冲突有关。我在尝试将最新版本的 Spring Boot 与 Apache Camel 一起使用时遇到了同样的问题。

分析依赖树,发现spring-webmvc的版本是5.2.9,其他spring依赖的都是5.2.8版本。

我已经通过使用更新版本的camel-spring-boot-dependencies (3.6.0) 解决了这个问题