首页 文章

没有明显原因的骆驼停止

提问于
浏览
1

我有一个bean生成器和一个bean使用者,在一个路由中使用 . 生产环境 者通过一个线程生成并监听一个hazelcast队列上的数据(它可能是其他任何东西,甚至是本地随机生成的数据我相信) .

数据被发送到seda endpoints ,以确保并发 . 消费者获取数据并将其转发到另一个hazelcast队列 . 但它又可能是其他任何东西 .

它运作良好,但过了一会儿,Camel关闭了,我找不到原因 .

以下是我看到的一些消息:

处理大量数据......

[                          main] MainSupport                    INFO  Apache Camel 2.10.3 stopping
[                          main] DefaultCamelContext            INFO  Apache Camel 2.10.3 (CamelContext: camel-1) is shutting down
[                          main] DefaultShutdownStrategy        INFO  Starting to graceful shutdown 1 routes (timeout 300 seconds)
[el-1) thread #2 - ShutdownTask] DefaultShutdownStrategy        INFO  Waiting as there are still 1 inflight and pending exchanges to complete, timeout in 300 seconds.

然后在300秒内处理并停止 .

这里有一些代码:

制片人:

public void run()
    {
        try
        {
            IRequest service = ProxyHelper.createProxy(context.getEndpoint("seda:echo"), IRequest.class);

            BlockingQueue<Request> q = client.getQueue(MainApp.sQueueReceive);

            while(true)
            {
                Request request;
                request = q.take();
                // no response awaited
                service.request(request);
            }
        }

消费者:

public void onMessage(Request request)
    {
        nb_forwarded++;
        BlockingQueue<Request> q = MainApp.client.getQueue(MainApp.sQueueForward);
        try
        {
            q.put(request);
        }
        catch (InterruptedException e)
        {
            exit(2);  --> it does not happen
        }

最后,路线:

from("seda:echo")
.setExchangePattern(ExchangePattern.InOnly)
.bean(new HazelcastForwarder(), "onMessage");

它在InOnly,因为没有人等待制作人的回应,它只是一个前锋 .

那么为什么Camel会停下来呢 . 那些说它正在停止的人没有消息 . Camel中是否存在此类默认行为 . 在哪些情况下?

谢谢!

2 回答

  • 1

    启用DEBUG或跟踪日志记录以揭示骆驼停止的真正原因 . 可能是封闭的容器正在停止(如果你在内部运行骆驼)或类似的 .

  • 0

    我遇到了类似的问题,Camel Context在启动流程后立即关闭 . 我发布在这里,以便它也可以帮助其他类似的问题 .

    在我的例子中,我使用Spring来使用' FileSystemXmlApplicationContext '加载Camel上下文并在try块中实例化它,

    try(AbstractXmlApplicationContext appContext = new FileSystemXmlApplicationContext(camelContextPath)) {
    
    }
    

    因为我的Eclipse抱怨资源泄漏 . 因此,一旦调用来自try / catch,它就关闭了Spring上下文,它再次关闭了Camel Context .

    要解决此问题,需要在try块中初始化Spring上下文 .

    AbstractXmlApplicationContext appContext = null;
    try {
        appContext = new FileSystemXmlApplicationContext(camelContextPath);
    
    }
    

相关问题