Apache Camel Mongodb 连接器异步

Apache Camel Mongodb Connector Async

是否可以将 MongoDBApache Camel 异步使用?

我没有在 Apache Camel 组件文档中看到任何关于 MongoDB 异步客户端或反应客户端的参考(MongoDB 有一个 async client and also a reactive streams client)。

A​​pache Camel 可以通过这种方式连接到它吗?

我很难理解 Apache Camel 通道适配器 (EIP) 是异步的还是同步的。如果有一种方法可以了解任何组件,这对我很有帮助。

Is it possible to use mongodb with Apache Camel asynchronously?

确实,这就是 Apache Camel 将在幕后进行的工作,否则,您会发现自己的应用程序被阻塞,无法继续进行任何有价值的处理。

由于您在 post 中提到了 Channel Adapter (EIP),我假设您正在尝试实施 MongoDB消费者。

为了使用来自 MongoDB 数据库的数据,Apache Camel 提供了两种使用策略:

  • Tailable Consumer: This strategy is about having a Thead continuously calling for next result on a MongoCursor. This strategy is feasible thanks to MongoDb Tailable Cursor 功能,即使在耗尽(迭代)结果后也可以打开查询游标,这样就无需连续让前者 Thread 一次又一次地执行提取查询
  • Change Stream Consumer: This strategy on the other hand relies on the MongoDB Changes watch 客户端可以接收(订阅后)特定集合更改的功能。与 Tailable 消费者相同,将有一个 Thread 运行 无休止地(除非停止)监听感兴趣的 MongoCollection 上的变化

如您所见,在这两种策略中,都不需要为更改处理执行直接查询,除非是初始引导和恢复,既不使用同步 Java Driver nor the Reactive Streams Driver.