Apache Camel Mongodb Connector Async

Viewed 57

Is it possible to use MongoDB with Apache Camel asynchronously?

I haven't seen any reference for the MongoDB async client or the reactive client in Apache Camel component documentation (MongoDB has an async client and also a reactive streams client).

Can Apache Camel connect to it in such ways?

I'm struggling to understand whether an Apache Camel channel adapter (EIP) is asynchronous or synchronous. If there's a way to know it for any component, this would be very helpful for me.

1 Answers

Is it possible to use mongodb with Apache Camel asynchronously?

Indeed, this is what Apache Camel will be doing under the cover, otherwise, you will find yourself with an application blocking without proceeding with any valuable processing.

Since you have referred to the Channel Adapter (EIP) in your post, I would assume you are trying to implement a MongoDB consumer.

To consume data from a MongoDB database, Apache Camel offers two consumer strategies:

  • 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 feature which simply allows to have a query cursor open even after exhausting (iterating) results which removes the need to continuously have the former Thread executing the fetch query again and again
  • Change Stream Consumer: This strategy on the other hand relies on the MongoDB Changes watch feature with which a client can receive (after subscription) changes for a particular collection. Same as for the Tailable consumer, there will be a Thread running endlessly (unless stopped) listening to changes on the MongoCollection of interest

As you can see, in both strategies, there is no need to perform direct queries for changes processing, unless for initial bootstrapping and resumption, neither using the synchronous Java Driver nor the Reactive Streams Driver.

Related