AxonFramework / extension-mongo

Axon Framework extension for Mongo integration as a Dead Letter, Event, Saga and Tracking Token storage solution.
https://axoniq.io/
Apache License 2.0
25 stars 16 forks source link

error Incompatible token type provided. when using mongo token store and spring boot #433

Closed Moh3n75 closed 3 months ago

Moh3n75 commented 4 months ago

Basic information

Steps to reproduce

when config axon token store to mongo db with this config :


 @Bean
    public EventStore eventStore(EventStorageEngine storageEngine, GlobalMetricRegistry globalMetricRegistry, SpanFactory spanFactory) {
        return EmbeddedEventStore.builder()
                .storageEngine(storageEngine)
                .messageMonitor(globalMetricRegistry.registerEventBus("eventStore"))
                .spanFactory(spanFactory)
                .build();
    }

    // The `MongoEventStorageEngine` stores each event in a separate MongoDB document
    @Bean
    public EventStorageEngine storageEngine(MongoDatabaseFactory factory, TransactionManager transactionManager, /*StorageStrategy storageStrategy,*/ Configurer configurer) {
        return MongoEventStorageEngine.builder()
                .mongoTemplate(SpringMongoTemplate.builder().factory(factory).build())
                .transactionManager(transactionManager)
                .eventSerializer(JacksonSerializer.defaultSerializer())
                //.storageStrategy(storageStrategy)
                .snapshotSerializer(JacksonSerializer.defaultSerializer())
                .upcasterChain(configurer.buildConfiguration().upcasterChain())
                .build();
    }

    @Bean
    public TokenStore myTokenStore(MongoDatabaseFactory factory) {
        return MongoTokenStore.builder()
                .mongoTemplate(SpringMongoTemplate.builder().factory(factory).build())
                .serializer(JacksonSerializer.defaultSerializer())
                .build();
    }

for tracking event store get error Incompatible token type provided. at this lines of code :

@Override
    public TrackingToken advancedTo(TrackingToken newToken) {
        if (this.tokenAtReset == null
                || (newToken.covers(WrappedToken.unwrapUpperBound(this.tokenAtReset))
                && !tokenAtReset.covers(WrappedToken.unwrapLowerBound(newToken)))) {
            // we're done replaying
            // if the token at reset was a wrapped token itself, we'll need to use that one to maintain progress.
            if (tokenAtReset instanceof WrappedToken) {
                return ((WrappedToken) tokenAtReset).advancedTo(newToken);
            }
            return newToken;
        } else if (tokenAtReset.covers(WrappedToken.unwrapLowerBound(newToken))) {
            // we're still well behind
            return new ReplayToken(tokenAtReset, newToken, context, true);
        } else {
            // we're getting an event that we didn't have before, but we haven't finished replaying either
            if (tokenAtReset instanceof WrappedToken) {
                return new ReplayToken(tokenAtReset.upperBound(newToken),
                                       ((WrappedToken) tokenAtReset).advancedTo(newToken),
                                       context,
                                       false);
            }
            return new ReplayToken(tokenAtReset.upperBound(newToken), newToken, context, false);
        }
    }

but when i use jpa token store tracking event store work correctly

please help me to find that error

abuijze commented 4 months ago

Could you provide the stack trace that you get? Did you first configure a JPAEventStorageEngine and then the MongoDB one? If so, did you reset (clear) the token table?

Moh3n75 commented 4 months ago

after debugging I found that .

its occurred when we use this dependency

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>

after remove its worked

smcvb commented 3 months ago

That's interesting, @Moh3n75, since as far as I know, Spring Boot Developer Tools should be working in combination with Axon Framework. However, I have a hunch what might be causing it, which is the version discrepancy between Axon Framework (4.9) and the Mongo Extension (4.6). It wouldn't hurt to use the latest version of the Mongo Extension here any how, but I am fairly confident it will fix use of the devtools dependency as well.

I will be closing this issue as resolved through the provided information and the fact you've solved it to some extent by simply removing spring-boot-devtools from the equation. If questions and/or problems remain on the subject, be sure to reach out!