骆驼FTP只能运行一次? [英] Camel-FTP only run once?

查看:101
本文介绍了骆驼FTP只能运行一次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当找不到文件时,我似乎无法使camel-ftp组件消失.

I can't seem to get the camel-ftp component to die when no files are found.

我添加了一个LimitedPollingConsumerPollStrategy,其限制为1:

I added a LimitedPollingConsumerPollStrategy with a limit of 1:

<bean id="noPoll" class="org.apache.camel.impl.LimitedPollingConsumerPollStrategy">
    <property name="limit" value="1"/>
</bean>

并配置URI以使用它:

and configured the URI to use it:

ftp://user@host.ftp/?password = pass& stepwise = false& binary = true& delete = false& noop = true& pollStrategy =#noPoll

当找不到文件时,它仍然挂起,寻找文件..所以我在URI中添加了&sendEmptyMessageWhenIdle=true.

It still just hangs, looking for files, when it doesn't find any.. so I added &sendEmptyMessageWhenIdle=true to the URI.

我在发送带有空正文的消息时在输出路由中添加了条件,并且看到了这些消息的泛滥,因此似乎对轮询使用者的限制无效.我尝试将其更改为&consumer.pollStrategy=#noPoll,并且其行为相同.

I added conditions to my route to output to log when a message comes through with a null body and I saw a flood of those messages so it seems the limit on the polling consumer isn't working. I tried changing it to &consumer.pollStrategy=#noPoll and it behaved the same.

推荐答案

如果没有使用任何消息,则以下PollStrategy将停止使用程序.

The following PollStrategy will stop the consumer if no messages are consumed.

public class PollOncePollStrategy extends DefaultPollingConsumerPollStrategy {

    @Override
    public void commit(Consumer consumer, Endpoint endpoint, int polledMessages) {
        try {
            if (polledMessages == 0) {
                log.info("No polled messages, stopping consumer");
                endpoint.getCamelContext().createProducerTemplate().sendBody(String.format("controlbus:route?async=true&action=stop&routeId=%s", EndpointHelper.getRouteIdFromEndpoint(endpoint)), null);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}

将其注册到骆驼注册表中,并按如下方式使用:ftp://127.0.0.1/mydir?pollStrategy=#pollOnce

Register it in the camel registry and use as follows: ftp://127.0.0.1/mydir?pollStrategy=#pollOnce

这篇关于骆驼FTP只能运行一次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆