Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a recommended solution on how to enable mongoDB "change streams" ? #497

Closed
michaelmosmann opened this issue Nov 16, 2023 Discussed in #496 · 7 comments
Closed
Assignees

Comments

@michaelmosmann
Copy link
Member

Discussed in #496

Originally posted by bodote November 15, 2023
MongoDB has a feature called "change streams". However, this feature is only available if there is a "replica set". The replica set in turn is NOT enabled by default for single instance MongoDBs. You can enable the replica set with de.flapdoodle.embed.mongo. But it seemes a little bit cumbersome though.

Is there any recommendation on how to use this with de.flapdoodle.embed.mongo ?

what we do is this:

 @Override
            public Transition<MongodArguments> mongodArguments() {
                return Start.to(MongodArguments.class)
                        .initializedWith(MongodArguments.defaults()
                                .withReplication(Storage.of("testRepSet", 5000))
                                .withUseNoJournal(false));
            }

plus :

 mongoClient.getDatabase("admin").runCommand(new Document("replSetInitiate", new Document()));

immediately @BeforeEach test.

especially the need for this admin - command above turned out to be somehow problematic and lead to unstable test until we wraped it part of the test code in some await().atMost(10, SECONDS).until(() -> {...}

Is there any better way ?

@michaelmosmann michaelmosmann self-assigned this Nov 16, 2023
@XSpielinbox
Copy link

Setting de.flapdoodle.mongodb.embedded.storage.repl-set-name=rs0 in the application.properties when using de.flapdoodle.embed.mongo.spring enables replicasets in a way that transactions seem to work. Maybe this does the trick here too?

@michaelmosmann
Copy link
Member Author

michaelmosmann commented Nov 17, 2023

@bodote
Copy link

bodote commented Nov 19, 2023

@XSpielinbox you are right, if you use the spring integration: https://github.com/flapdoodle-oss/de.flapdoodle.embed.mongo.spring/blob/041421695626591599798602a39df8a61e3fdb42/src/main/java/de/flapdoodle/embed/mongo/spring/autoconfigure/AbstractServerFactory.java#L84

maybe it is time for an backport:)

If its already in the spring3.1.x branch of https://github.com/flapdoodle-oss/de.flapdoodle.embed.mongo.spring/ , which I use anyhow, it would be nice, if there would be an explationaion in the HowTo.md how to use this autoconfigure/AbstractServerFactory, because it is not clear to me.
Is setting the de.flapdoodle.mongodb.embedded.storage.repl-set-name=rs0 really all you need to do ?

@michaelmosmann
Copy link
Member Author

@bodote yes.. the setting is all you need, as everything else will be configured from that (using AbstractServerFactory etc).

@bodote
Copy link

bodote commented Nov 19, 2023

de.flapdoodle.mongodb.embedded

I see, thank you.
BTW using "de.flapdoodle.mongodb.embedded." and "de.flapdoodle.embed.mongo." for properties is really confusing, and can easily get mixed up which would lead to wrongly setting properties which are not working.

@michaelmosmann
Copy link
Member Author

@bodote hmmm.. i may fix this with the next mayor release.. i think it was 'spring.mongodb.embedded' .. and i changed it to 'de.flapdoodle.mongodb.embedded' ..

@michaelmosmann
Copy link
Member Author

moved it to an new issue.. so i close this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants