65.10. Pausable Consumers
Kafka 组件支持 pausable 用户。这种类型的消费者可以根据组件本身以外的条件暂停消耗数据,如外部系统不可用或其他临时条件。
from("kafka:topic") .pausable(new KafkaConsumerListener(), () -> canContinue()) // the pausable check gets called if the exchange fails to be processed ... .routeId("pausable-route") .process(this::process) // Kafka consumer will be paused if this one throws an exception ... .to("some:destination"); // or this one
from("kafka:topic")
.pausable(new KafkaConsumerListener(), () -> canContinue()) // the pausable check gets called if the exchange fails to be processed ...
.routeId("pausable-route")
.process(this::process) // Kafka consumer will be paused if this one throws an exception ...
.to("some:destination"); // or this one
在本例中,如果来自 canContinue
的结果为 false,消耗的信息可能会暂停(调用 Kafka 的 Consumer pause 方法)。
重要
当路由中有 异常阻止交换被处理时, 可以使用 pausable EIP 作为支持机制。更具体地说,应该使用 pausable
EIP 调用的检查来测试阻止交换处理的临时条件。
注意
大多数用户应更喜欢使用,这可以为路由提供更好的控制。