5

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.

rotemjac
  • 51
  • 1
  • 3
  • Could you elaborate your questions ? 1) other than the example provided in the manual, what kind of best practices are you looking for ? if you could include some design decision or question that would be good. 2) Why is a single thread per collection less desirable ? what are you trying to do for example ? – Wan B. Mar 16 '18 at 00:08

2 Answers2

1

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.

-1

Use mongo reactive driver so that it will be non-blocking. And we used this approach and running in production for last one month, no issue.

Ash
  • 1,210
  • 1
  • 10
  • 14