我设置了一些路线(骆驼2.22.1),这些路线使用窃听将一些东西记录到Mongo数据库中。
from(DIRECT_NEXT).process(sendFile)
.wireTap( "direct:count-fetch?failIfNoConsumers=false" )
如您所见,我正在使用 failIfNoConsumers = false 。
from(COUNT_FETCH)
.routeId( MONGO_COUNT_FETCH_ROUTEID )
.autoStartup( false )
.process(countFetchProcessor)
.to(persistenceEndpoints.updateImage())
.log(LoggingLevel.DEBUG, "Counted fetch.");
mongo数据库是可选组件,没有它,整个应用程序将运行。
我正在使用Mongo的ServerMonitorListener检查Mongo是否可用。我相应地使用Camel的ControlBus暂停或恢复了溃败。
一切正常! 我的问题是骆驼尝试将交换机发送到30秒钟未运行的路由:
...
[DEBUG] 2019-01-03 14:02:45.848 [Camel (camel-1) thread #23 - WireTap] DirectBlockingProducer - Waited 20025 for consumer to be ready
...
为什么生产者封锁了? “ block”的默认值应该为false ?! 之后,我们当然会看到一个例外:
No consumers available on endpoint: direct://count-fetch?failIfNoConsumers=false
让骆驼立即丢弃交换(如何设置超时时间)并且不引发任何异常(因为这是正常的应用程序行为,异常只会减慢速度)的最佳方法是什么?
更新: 这是完整的例外:
[ERROR] 2019-01-07 10:21:22.702 [Camel (camel-1) thread #4 - WireTap] DefaultErrorHandler - Failed delivery for (MessageId: ID-moritz-1546852848013-0-3 on ExchangeId: ID-moritz-1546852848013-0-2). Exhausted after delivery attempt: 1 caught: org.apache.camel.component.direct.DirectConsumerNotAvailableException: No consumers available on endpoint: direct://update-all?failIfNoConsumers=false. Exchange[ID-moritz-1546852848013-0-2]
Message History
---------------------------------------------------------------------------------------------------------------------------------------
RouteId ProcessorId Processor Elapsed (ms)
[route4 ] [route4 ] [timer://updateAll ] [ 30065]
[route4 ] [log1 ] [log ] [ 1]
[route4 ] [to3 ] [direct:updateAll ] [ 19]
[route5 ] [process2 ] [Processor@0x4e92466a ] [ 9]
[route5 ] [process3 ] [Processor@0x1b29d52b ] [ 7]
[route5 ] [wireTap1 ] [wireTap[direct:update-all?failIfNoConsumers=false] ] [ 1]
Stacktrace
---------------------------------------------------------------------------------------------------------------------------------------
org.apache.camel.component.direct.DirectConsumerNotAvailableException: No consumers available on endpoint: direct://update-all?failIfNoConsumers=false. Exchange[ID-moritz-1546852848013-0-2]
at org.apache.camel.component.direct.DirectBlockingProducer.getConsumer(DirectBlockingProducer.java:67) ~[camel-core-2.22.1.jar:2.22.1]
at org.apache.camel.component.direct.DirectBlockingProducer.process(DirectBlockingProducer.java:53) ~[camel-core-2.22.1.jar:2.22.1]
at org.apache.camel.processor.SendDynamicProcessor$1.doInAsyncProducer(SendDynamicProcessor.java:178) ~[camel-core-2.22.1.jar:2.22.1]
at org.apache.camel.impl.ProducerCache.doInAsyncProducer(ProducerCache.java:445) ~[camel-core-2.22.1.jar:2.22.1]
at org.apache.camel.processor.SendDynamicProcessor.process(SendDynamicProcessor.java:160) ~[camel-core-2.22.1.jar:2.22.1]
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:548) [camel-core-2.22.1.jar:2.22.1]
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201) [camel-core-2.22.1.jar:2.22.1]
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:97) [camel-core-2.22.1.jar:2.22.1]
at org.apache.camel.processor.WireTapProcessor$1.call(WireTapProcessor.java:160) [camel-core-2.22.1.jar:2.22.1]
at org.apache.camel.processor.WireTapProcessor$1.call(WireTapProcessor.java:155) [camel-core-2.22.1.jar:2.22.1]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_181]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_181]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_181]
at java.lang.Thread.run(Thread.java:748) [?:1.8.0_181]
答案 0 :(得分:1)
请确保检查文档以了解您使用的Camel版本,即2.22.x
您可以看到该块已默认启用:https://github.com/apache/camel/blob/camel-2.22.x/camel-core/src/main/docs/direct-component.adoc