【问题标题】:Camel process receivnig hang up singal and shutsdown gracefully骆驼进程接收挂断信号并优雅关闭
【发布时间】:2019-02-01 02:19:40
【问题描述】:

我有一个 Camel 进程,它从 Azure 容器中提取文件并在 Azure 环境中处理它。

我希望进程连续运行,但它会在随机间隔后关闭。

日志:

CamelHangupInterceptor: INFO (MainSupport.java:87) - Received hang up - stopping the main instance.
CamelHangupInterceptor: DEBUG (Main.java:187) - Stopping Spring ApplicationContext: org.springframework.context.support.ClassPathXmlApplicationContext@47ef968d
2019-01-29 21:39:50,782: main: INFO (MainSupport.java:502) - MainSupport exiting code: 0

... 自使用 DefaultShutdownStrategy 以来,在机上交换完成后关闭所有路由。

Spring上下文路由:

- Start with a scheduler for initial delay,
- then <dealy> component to randomly generate time (logic used for scalability to avoid race condition)
- invoking the custom class implementing Process class, which has Azure container url with credentials and fetch the file from container
- then using wireTap component to downloading the file
- finally invoking another class implementing Process class.

Camel (v 2.20) 进程按预期启动和执行,但在随机间隔后进程关闭。

我看到收到挂断信号,但不确定它是如何发生的。日志显示正常关机。有没有办法从外部进程向 Camel 进程发送挂断信号?

在我用来停止交换的路线之一中强行停止该路线。

 exchange.setProperty(Exchange.ROUTE_STOP, Boolean.TRUE);

更多日志:

 2019-01-29 21:40:17,838: Camel Thread #0 - CamelHangupInterceptor: DEBUG (DefaultExecutorServiceManager.java:363) - Forcing shutdown of ExecutorService: org.apache.camel.util.concurrent.RejectableThreadPoolExecutor@647b9364[Running, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0][WireTap]
    ...
        2019-01-29 21:40:17,840: Camel Thread #0 - CamelHangupInterceptor: DEBUG (RouteService.java:289) - Shutting down services on route: route1
        2019-01-29 21:40:17,841: Camel Thread #0 - CamelHangupInterceptor: DEBUG (BeanComponent.java:72) - Clearing BeanInfo cache[size=1, hits=1, misses=1, evicted=0]
        2019-01-29 21:40:17,849: Camel Thread #0 - CamelHangupInterceptor: DEBUG (SimpleLanguage.java:136) - Clearing simple language predicate cache[size=0, hits=0, misses=0, evicted=0]
        2019-01-29 21:40:17,849: Camel Thread #0 - CamelHangupInterceptor: DEBUG (SimpleLanguage.java:142) - Clearing simple language expression cache[size=4, hits=1, misses=4, evicted=0]
        2019-01-29 21:40:17,849: Camel Thread #0 - CamelHangupInterceptor: DEBUG (DefaultManagementAgent.java:358) - Unregistered MBean with ObjectName: org.apache.camel:context=camelAzureBlobContext,type=routecontroller,name="camelAzureBlobContext"
        2019-01-29 21:40:17,849: Camel Thread #0 - CamelHangupInterceptor: DEBUG (DefaultManagementAgent.java:358) - Unregistered MBean with ObjectName: org.apache.camel:context=camelAzureBlobContext,type=health,name="camelAzureBlobContext"
        2019-01-29 21:40:17,850: Camel Thread #0 - CamelHangupInterceptor: DEBUG (TimerListenerManager.java:128) - Removed TimerListener: org.apache.camel.management.mbean.ManagedCamelContext@473692b
        2019-01-29 21:40:17,850: Camel Thread #0 - CamelHangupInterceptor: DEBUG (DefaultManagementAgent.java:358) - Unregistered MBean with ObjectName: org.apache.camel:context=camelAzureBlobContext,type=context,name="camelAzureBlobContext"
        2019-01-29 21:40:17,850: Camel Thread #0 - CamelHangupInterceptor: INFO (MainLifecycleStrategy.java:44) - CamelContext: camelAzureBlobContext has been shutdown, triggering shutdown of the JVM.
        2019-01-29 21:40:17,850: Camel Thread #0 - CamelHangupInterceptor: DEBUG (DefaultExecutorServiceManager.java:363) - Forcing shutdown of ExecutorService: org.apache.camel.util.concurrent.RejectableThreadPoolExecutor@72b68833[Running, pool size = 1, active threads = 0, queued tasks = 0, completed tasks = 1][ShutdownTask]
        2019-01-29 21:40:17,851: Camel Thread #0 - CamelHangupInterceptor: DEBUG (DefaultInflightRepository.java:183) - Shutting down with no inflight exchanges.
        2019-01-29 21:40:17,851: Camel Thread #0 - CamelHangupInterceptor: DEBUG (DefaultServicePool.java:110) - Stopping service pool: org.apache.camel.impl.SharedPollingConsumerServicePool@13ed066e
        2019-01-29 21:40:17,851: Camel Thread #0 - CamelHangupInterceptor: DEBUG (DefaultServicePool.java:110) - Stopping service pool: org.apache.camel.impl.SharedProducerServicePool@151ab2b9
    ...
    2019-01-29 21:40:17,856: Camel Thread #0 - CamelHangupInterceptor: DEBUG (MBeanInfoAssembler.java:79) - Clearing cache[size=30, hits=12, misses=30, evicted=0]
    2019-01-29 21:40:17,864: Camel Thread #0 - CamelHangupInterceptor: DEBUG (IntrospectionSupport.java:134) - Clearing cache[size=93, hits=192, misses=93, evicted=0]
    2019-01-29 21:40:17,869: Camel Thread #0 - CamelHangupInterceptor: INFO (DefaultCamelContext.java:3575) - Apache Camel 2.20.0 (CamelContext: camelAzureBlobContext) uptime 32 minutes

-- 路线信息--

<camel:camelContext id="camelAzureBlobContext" xmlns="http://camel.apache.org/schema/spring" typeConverterStatisticsEnabled="true" autoStartup="true">
    <endpoint id="listBlobendpoint"
        uri="azure-blob://storageaccount/containerName?credentials=containercredientiasl&amp;operation=listBlobs" /> <!-- changed the actual values -->

    <dataFormats>
        <json id="inputMsg" library="Jackson" unmarshalTypeName="pacakage.requiredinputpojojacksonclass" />  <!-- renamed the class name-->
    </dataFormats>
    <onException>
        <exception>com.fasterxml.jackson.core.JsonParseException</exception>
        <exception>com.fasterxml.jackson.databind.JsonMappingException</exception>
        <handled>
            <constant>true</constant>
        </handled>
        <process ref="parseExceptionResponse" />
    </onException>
    <route>
        <from uri="scheduler://tempScheduler?initialDelay=5000&amp;delay=50000" /> <!-- changed the actual values -->
        <setHeader headerName="BlobListingDetails">
            <simple resultType="com.microsoft.azure.storage.blob.BlobListingDetails">METADATA</simple>
        </setHeader>
        <delay>
            <method ref="blobcamelprocess" method="randomDelayToPoll"></method> <!-- Method which has some random number generation-->
        </delay>
        <to uri="ref:listBlobendpoint" /> <!-- bean which actually sets the metadata value-->
        <process ref="blobcamelprocess" />
        <!-- creating recipient list to update metadata of the container blob file -->
        <recipientList>
            <header>update_metadata</header>
        </recipientList>
        <log message="Message | $simple{in.header[filename]}" loggingLevel="INFO"></log>
        <wireTap uri="file://location?fileName=$simple{in.header[filename]}"/>
        <unmarshal ref="inputMsg" />
        <process ref="messageconversionprocess" /> <!-- bean which actually converts uses the parsed json to construct java object-->
        <process ref="deleteblobProcess" /> <!-- bean that will be used to delete the file from the blob store -->
        <recipientList>
            <header>delete_blob</header> <!-- endpoint details is set from the above bean and passed here -->
        </recipientList>
    </route>    
</camel:camelContext>

【问题讨论】:

    标签: java apache-camel


    【解决方案1】:

    根据日志,您的整个 Camel 上下文正在关闭。上下文关闭不太可能是由您的 ROUTE_STOP 调用启动的。

    查看MainSupport.java 源,您在日志文件中看到的 INFO 日志作为挂断通知挂钩的一部分执行,由正在进行的 JVM 关闭通知。当这种情况发生时,你的 JVM 也会死掉吗? This documentation 表示当 SIGINT、SIGTERM 或 SIGHUP 发起 JVM 异常终止时会通知钩子

    如果您能提供以下问题的答案,或许我们可以进一步了解详情

    • Camel 是在 Web 容器中运行还是在其他东西中运行?我看到 MainSupport.java :)
    • 您使用什么 JVM 版本?
    • 它在什么操作系统平台上运行?
    • 当 Camel 上下文关闭时,JVM 是否仍在运行或 JVM 也退出?
    • 您是否在日志文件中看到其他异常?
    • 我们能否将此 CamelContext 关闭与系统资源耗尽事件相关联? (比如内存不足或类似的东西)。不太可能成为 OOMKiller,因为它是优雅的关闭。

    附带说明,不要被 CamelHangupInterceptor 这个名字误导,这并不意味着 Camel 收到了 SIGHUP

    【讨论】:

    • JRE (SE) 版本 1.8.0_131 (hotspot build 25.131-b11) 64 位 Camel 进程正在 Azure Vm (centos 7) 上运行 是 Camel 上下文也关闭了 JVM。
    • 所以没有 OutOfMemoryException 或任何类似的痕迹。您为jvm 分配了多少堆? Azure VM 有多少内存?当此事件发生时,您是否在操作系统事件日志中看到任何相关内容(使用 journalctl 或等效项检查)?在“骆驼上下文也关闭了 JVM”中,我有一种强烈的反感。也许它也值得发布您的 RouteBuilder(s)。
    • 这有点牵强,但您的应用程序是否有可能从某个地方收到 JMX 关闭?尝试使用context.disableJMX() 启动骆驼上下文。这个应用程序如何在 Centos 盒子上启动?它是作为systemd 服务启动的吗?
    • 我在 Camel 项目的 gitter 频道上引用了这篇文章,以便对框架有更深入了解的人也可以看看
    • 在我的情况下,进程被操作系统杀死,因为虚拟机(centos 7.2)是使用 Chef 配置的,作为守护线程运行的 chef 客户端通常会杀死正在运行的进程,因为如果 chef 调用了 stop shell标签丢失。调试步骤很少,我使用了 $ strace -tt -o outfilename.out -p & $ service --status-all $ jstat -l $ jmap => 使用 Eclipse 堆分析器分析转储
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-09-29
    • 2019-12-01
    • 2012-08-22
    • 1970-01-01
    • 2016-10-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多