Camel-FTP 只运行一次? [英] Camel-FTP only run once?
问题描述
当找不到文件时,我似乎无法让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:
当它没有找到任何文件时,它仍然挂起,寻找文件.所以我将 &sendEmptyMessageWhenIdle=true
添加到 URI.
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);
}
}
}
在camel注册表中注册,使用如下: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
这篇关于Camel-FTP 只运行一次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!