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

No Spring Boot Auto configuration #230

Closed
frederic-gendebien opened this issue May 24, 2022 · 1 comment · Fixed by #287
Closed

No Spring Boot Auto configuration #230

frederic-gendebien opened this issue May 24, 2022 · 1 comment · Fixed by #287

Comments

@frederic-gendebien
Copy link

Enhancement Description

I think it would be interesting to offer an Auto configuration for the mongo implementations of the given components:

  • TokenStore
  • SagaStore

Current Behaviour

I have these artefacts in my dependencies:

  • axon-spring-boot-starter
  • axon-mongo

The following components are not provided out of the box:

  • TokenStore
  • SagaStore

Wanted Behaviour

I expected to have the same behaviour as JPA, meaning that the components mentioned above should be provided. I think for clarity we could create another module like 'axon-mongo-...-starter'.

Possible Workarounds

I created a module in my project to work around this:

package org.karamelsoft.axon.demo.libraries.mongo

import com.mongodb.client.MongoClient
import org.axonframework.config.Configurer
import org.axonframework.eventhandling.tokenstore.TokenStore
import org.axonframework.extensions.mongo.DefaultMongoTemplate
import org.axonframework.extensions.mongo.MongoTemplate
import org.axonframework.extensions.mongo.eventhandling.saga.repository.MongoSagaStore
import org.axonframework.extensions.mongo.eventsourcing.tokenstore.MongoTokenStore
import org.axonframework.modelling.saga.repository.SagaStore
import org.axonframework.serialization.Serializer
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.context.annotation.Configuration

private const val AXON_SAGAS = "axon_sagas"
private const val AXON_TOKENS = "axon_tokens"

@Configuration
class MongoAutoConfiguration {

    private val logger: Logger = LoggerFactory.getLogger(MongoAutoConfiguration::class.java)

    @Autowired
    fun configuration(configurer: Configurer, mongoClient: MongoClient, serializer: Serializer) {
        val mongoTemplate = DefaultMongoTemplate.builder()
            .mongoDatabase(mongoClient)
            .sagasCollectionName(AXON_SAGAS)
            .trackingTokensCollectionName(AXON_TOKENS)
            .build()

        configurer
            .eventProcessing { eventProcessingConfigurer ->
                eventProcessingConfigurer
                    .registerSagaStore { conf -> mongoSagaStore(mongoTemplate, conf.serializer()) }
                    .registerTokenStore { conf -> mongoTokenStore(mongoTemplate, conf.serializer()) }
            }
    }

    fun mongoTokenStore(mongoTemplate: MongoTemplate, serializer: Serializer): TokenStore {
        logger.info("Creating mongodb token store")
        return MongoTokenStore.builder()
            .mongoTemplate(mongoTemplate)
            .serializer(serializer)
            .build()
    }

    fun mongoSagaStore(mongoTemplate: MongoTemplate, serializer: Serializer): SagaStore<Any> {
        logger.info("Creating mongodb saga store")
        return MongoSagaStore.builder()
            .mongoTemplate(mongoTemplate)
            .serializer(serializer)
            .build()
    }
}
@gklijs gklijs added this to the Release 4.6.1 milestone Sep 26, 2022
@gklijs gklijs self-assigned this Oct 24, 2022
@gklijs
Copy link
Collaborator

gklijs commented Oct 24, 2022

Add a Spring module with at least:

  • A SpringMongoTemplate to ensure the factory is used each time to get the database, to ensure transaction works, see transaction test project.
  • Default to use the SpringTransactionmanager based on the Spring MongoTransactionManager as the transaction manager.
  • Have simple true/false properties to enable parts. By default, create the TokenStore, SequecencedDeadletterQueue and Sagastore and not the EventStorageEngine.

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

Successfully merging a pull request may close this issue.

3 participants