Replacement for ClientSession when not using transactions #615
-
When using Spring Boot 3 (Webflux) with mongock-springboot-v3 and mongodb-reactive-driver and transactions disabled the code @ChangeUnit(id = "test", order = "3", author = "test")
@Slf4j
public class MongockExperiment {
private final ReactiveMongoTemplate reactiveMongoTemplate;
public MongockExperiment(ReactiveMongoTemplate reactiveMongoTemplate) {
this.reactiveMongoTemplate = reactiveMongoTemplate;
}
/**
* Add criteria and event type
**/
@Execution
public void migrate() {
reactiveMongoTemplate.findAll(UserDTO.class).collectList().delayElement(Duration.of(3, ChronoUnit.SECONDS)).flatMapMany(list -> {
list.forEach(user -> user.setFirstName(user.getFirstName() + "test"));
return Flux.fromIterable(list);
}).flatMap(reactiveMongoTemplate::save).subscribe();
} produces the following error:
I suppose it is due to interweaving of multiple operations. All online Examples I could finde of Mongock use |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
Hi @XSpielinbox , As @osantana85 mentioned in the issue you raised, we are adding the Reactive driver for Spring data v4 (as well as the documentation for Springboot 3.x). So, in the meanwhile(and corroborated by your comment in the issue's description If that's true, I am a bit confused
Thanks |
Beta Was this translation helpful? Give feedback.
-
Hi again. lets divide this into smaller issues: Error
|
Beta Was this translation helpful? Give feedback.
Hi again. lets divide this into smaller issues:
Error
Lock cannot be ensured after being cancelled
This is better explained in the official documentation. It just says that although Mongock's nature is synchronous, you can still use reactive. However, you must block the sync call in the changeUnits(obviously not need to do so in the rest of your application). You can see an example here
The reason behind this is that the distributed lock is acquired before starting the process, then each changeUnit is applied synchronously(at least that's the expectation) and then the lock is released. Keep in mind that Mongock provides a very robust lock mechanism, so every I/O call you make within a cha…