Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mongodb change streams java

Since this feature is relatively new (mongo 3.6) I found very few java examples. My questions: 1. What is the best practices for watching change streams? 2. Does it have to be a blocking call to watch the stream? (This means a thread per collection which is less desired) This is the example I encountered:

http://mongodb.github.io/mongo-java-driver/3.6/driver/tutorials/change-streams/

The blocking call is: collection.watch().forEach(printBlock);

Thanks, Rotem.

like image 751
rotemjac Avatar asked Nov 07 '22 09:11

rotemjac


1 Answers

Change streams make a lot more sense when you look at them in the context of reactive streams. It took me a while to realize this concept has a much broader existence than just the MongoDB driver.

I recommend reviewing the article above and then looking at the example provided here. The two links helped clear things up, and provided insight on how to write code leveraging the reactive streams Mongo driver, which is non-blocking.

like image 148
Mitch Francis Avatar answered Nov 15 '22 05:11

Mitch Francis