spring-native icon indicating copy to clipboard operation
spring-native copied to clipboard

Mongo Change Streams Doesn't Work with v0.12.x

Open SentryMan opened this issue 3 years ago • 9 comments

So, I'm working with Mongo change streams.

reactiveMongoTemplate.changeStream("Manga", FULL_DOC, Manga.class) But I'm getting this error when I try to subscribe to events:

Error processing com.mongodb.reactivestreams.client.internal.MongoDatabaseImpl@414f8bf8 Exception is org.bson.codecs.configuration.CodecConfigurationException: Invalid @BsonCreator constructor in ChangeStreamDocument. Invalid Property type for 'operationType'. Expected class com.mongodb.client.model.changestream.OperationType, found class java.lang.String.

I have added the ChangeStreamDocument class to my reflection config, and It works fine when I'm not running on the binary.

Here is my repo: https://github.com/SentryMan/Manga-Spring-Backend/blob/8bd0c2367265fc4e7fedb67be2aecd9deb4e4816/src/main/java/com/mangasite/services/MangaService.java#L94-L95

SentryMan avatar Aug 29 '22 02:08 SentryMan

Maybe you miss a type/reflection hint on com.mongodb.client.model.changestream.OperationType.

sdeleuze avatar Aug 30 '22 12:08 sdeleuze

Yeah, this doesn't work https://github.com/SentryMan/Manga-Spring-Backend/commit/5d3ee9c8bc27286abefb89e5bedc900c44fac788

Also, I had it working before without needing to add reflection. I only recently noticed it had stopped working. I personally suspect that when this constructor got deprecated something broke.

    @Deprecated
    public ChangeStreamDocument(final OperationType operationType,
            final BsonDocument resumeToken,
            final BsonDocument namespaceDocument,
            final BsonDocument destinationNamespaceDocument,
            final TDocument fullDocument,
            final BsonDocument documentKey,
            final BsonTimestamp clusterTime,
            final UpdateDescription updateDescription,
            final BsonInt64 txnNumber,
            final BsonDocument lsid) 

SentryMan avatar Aug 31 '22 00:08 SentryMan

Your repro is using an outdated RC, please use Spring Native 0.12.1 with latest Spring Boot 2.7.x version.

sdeleuze avatar Aug 31 '22 07:08 sdeleuze

That was the first thing I tried. https://github.com/SentryMan/Manga-Spring-Backend/blob/a9931a7876e45f3c55694e8d698df2c14edfe6eb/pom.xml On the fix branch I was running 2.7.3 with 0.12.1

SentryMan avatar Aug 31 '22 13:08 SentryMan

It seems when I revert the version to spring native 11.4 / 2.6.6 it works

SentryMan avatar Sep 01 '22 01:09 SentryMan

Yeah, the problem seems to start at v0.12.0

SentryMan avatar Sep 01 '22 02:09 SentryMan

Could be missing reflection hints on the parameters that are used to identify the new constructor reflectively. Please make a try with reflection hints for all the parameter types used in ChangeStreamDocument constructors.

sdeleuze avatar Sep 07 '22 08:09 sdeleuze

That also didn't work

SentryMan avatar Sep 08 '22 23:09 SentryMan

How shall we proceed?

SentryMan avatar Sep 15 '22 04:09 SentryMan

I tried https://github.com/SentryMan/Manga-Spring-Backend/blob/a9931a7876e45f3c55694e8d698df2c14edfe6eb/pom.xml, but when running it with mvn spring-boot:build-image + docker run docker.io/library/manga-backend:3.0.0, I get a Could not resolve placeholder 'SECRET_KEY' in value "${SECRET_KEY}". So if you want some help from me, please provide a repro that works, some thing where for example Mongo and the native app runs via Docker Compose with the various environnement variable set.

sdeleuze avatar Sep 23 '22 08:09 sdeleuze

I have created an example repo to show this error https://github.com/SentryMan/Spring-Native-Mongo-Change-Stream

SentryMan avatar Sep 26 '22 17:09 SentryMan

Spring Native is now superseded by Spring Boot 3 official native support, see the related reference documentation for more details.

As a consequence, I am closing this issue, and recommend trying your use case with latest Spring Boot 3 version. If you still experience the issue reported here, please open an issue directly on the related Spring project (Spring Framework, Data, Security, Boot, Cloud, etc.) with a reproducer.

Thanks for your contribution on the experimental Spring Native project, we hope you will enjoy the official native support introduced by Spring Boot 3.

sdeleuze avatar Jan 02 '23 11:01 sdeleuze