Class MongoSagaStore
The document layout is that of Axon Framework 4, so an existing sagas collection can be read and updated without
migration, provided its sagaType field holds saga class names. Axon Framework 4 derived that field through
its Serializer, which for the default configuration also produced the class name. An application that mapped
its saga classes to some other type name, an XStream alias being the usual way, has documents this store cannot route
to and must rewrite that field to the class name first.
The saga state itself is converted with the configured Converter. Axon Framework 4 defaulted to the
XStreamSerializer unless the application configured another serializer, so the stored state of such an
application is XStream XML, which a JSON-based converter cannot read: loading such a saga fails. Give this store an
XStreamConverter if you are migrating such a scenario to read that state
and to write it back in the same form, which also lets Axon Framework 4 nodes keep handling the same sagas during a
rolling upgrade.
Note that sagaType records the class of the saga instance handed to
insertSaga(Class, String, Object, Set), which is not necessarily the sagaType argument. Loading, on
the other hand, matches on the identifier alone and ignores the type entirely.
This store performs one Mongo operation per call, so it manages no transaction of its own beyond whatever the
TransactionManager it was given provides. That defaults to NoTransactionManager, as it did in Axon
Framework 4, under which a call commits on its own.
- Since:
- 2.0
- Author:
- Jettro Coenradie, Allard Buijze
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface org.axonframework.modelling.saga.repository.SagaStore
SagaStore.Entry<T> -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedMongoSagaStore(MongoSagaStore.Builder builder) Instantiate aMongoSagaStorebased on the fields contained in theMongoSagaStore.Builder. -
Method Summary
Modifier and TypeMethodDescriptionstatic MongoSagaStore.Builderbuilder()Instantiate a Builder to be able to create aMongoSagaStore.voiddeleteSaga(Class<?> sagaType, String sagaIdentifier, Set<AssociationValue> associationValues) Deletes a Saga with givensagaTypeandsagaIdentifierand all its associations.findSagas(Class<?> sagaType, AssociationValue associationValue) Returns identifiers of saga instances of the givensagaTypethat have been associated with the givenassociationValue.voidinsertSaga(Class<?> sagaType, String sagaIdentifier, Object saga, Set<AssociationValue> associationValues) Adds a new Saga and its initial association values to the store.<S> @Nullable SagaStore.Entry<S> voidupdateSaga(Class<?> sagaType, String sagaIdentifier, Object saga, AssociationValues associationValues) Updates a given Saga after its state was modified, applying the association values added and removed since it was last stored.
-
Constructor Details
-
MongoSagaStore
Instantiate aMongoSagaStorebased on the fields contained in theMongoSagaStore.Builder.Will assert that the
MongoTemplateandConverterare notnull, and will throw anAxonConfigurationExceptionif any of them isnull.- Parameters:
builder- theMongoSagaStore.Builderused to instantiate aMongoSagaStoreinstance
-
-
Method Details
-
builder
Instantiate a Builder to be able to create aMongoSagaStore.The
MongoTemplateandConverterare hard requirements and as such should be provided. TheTransactionManageris defaulted to aNoTransactionManager.- Returns:
- a Builder to be able to create a
MongoSagaStore
-
loadSaga
Description copied from interface:SagaStoreLoads a known sagaSagaStore.Entryinstance with givensagaTypeand uniquesagaIdentifier.Due to the concurrent nature of Sagas, it is not unlikely for a Saga to have ceased to exist after it has been found based on associations. Therefore, a repository should return
nullin case a Saga doesn't exists, as opposed to throwing an exception. -
findSagas
Description copied from interface:SagaStoreReturns identifiers of saga instances of the givensagaTypethat have been associated with the givenassociationValue. -
deleteSaga
public void deleteSaga(Class<?> sagaType, String sagaIdentifier, Set<AssociationValue> associationValues) Description copied from interface:SagaStoreDeletes a Saga with givensagaTypeandsagaIdentifierand all its associations. For convenience all known association values are passed along as well, which has the advantage that the saga store is not required to keep an index of association value to saga identifier.- Specified by:
deleteSagain interfaceSagaStore<Object>- Parameters:
sagaType- The type of saga to deletesagaIdentifier- The identifier of the saga to deleteassociationValues- The known associations of the saga
-
updateSaga
public void updateSaga(Class<?> sagaType, String sagaIdentifier, Object saga, AssociationValues associationValues) Description copied from interface:SagaStoreUpdates a given Saga after its state was modified, applying the association values added and removed since it was last stored.- Specified by:
updateSagain interfaceSagaStore<Object>- Parameters:
sagaType- The type of the SagasagaIdentifier- The identifier of the Sagasaga- The Saga instanceassociationValues- The association values of the Saga, carrying the additions and removals to apply
-
insertSaga
public void insertSaga(Class<?> sagaType, String sagaIdentifier, Object saga, Set<AssociationValue> associationValues) Description copied from interface:SagaStoreAdds a new Saga and its initial association values to the store.- Specified by:
insertSagain interfaceSagaStore<Object>- Parameters:
sagaType- The type of the SagasagaIdentifier- The identifier of the Sagasaga- The Saga instanceassociationValues- The initial association values of the Saga
-