【问题标题】:The camel context initiates shutdown immediately after application start, with no apparent error骆驼上下文在应用程序启动后立即启动关闭,没有明显的错误
【发布时间】:2019-10-21 17:59:22
【问题描述】:

我的 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 开始关闭...

【问题讨论】:

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


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    这个和spring版本升级有关。

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

    分析了依赖树,原来spring-webmvc的版本是5.2.9,而其他的spring依赖都是5.2.8版本。

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

    【讨论】:

      【解决方案3】:

      最终,这个解决方案奏效了:

      @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();
          }
      }
      

      【讨论】:

      • 这在本地不起作用,因为 junit 不会停止并且构建会继续进行。
      【解决方案4】:

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

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

      我会选择网络容器。因此,您还可以添加带有一些诊断信息的执行器框架。

      【讨论】:

      • 我的 pom.xml 中已经有了 spring-boot-starter-web 依赖项
      • 在我的 spring-boot 项目中添加一个 web 容器“spring-boot-starter-web”依赖解决了我遇到的类似问题。谢谢@Simon
      • 我认为这些方法中的任何一个都不是推荐的方法。添加camel.springboot.main-run-controller = true 怎么样
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多