Hi,
I am having problem in using MongoSagaStore. I have a saga implementation like following. After setting the value for item attribute in one event handler and later when I try to get the value in another event handler the value is null.
I don’t face this problem when using JpaSagaStore.
@Saga(sagaStore = “mongoSagaStore”)
@ProcessingGroup(“OrderSaga”)
public class OrderManagementSaga implements Serializable {
private static final long serialVersionUID = 4573830325124783880L;
@Inject
private transient CommandGateway commandGateway;
private String item;
@StartSaga
@SagaEventHandler(associationProperty = “orderId”)
public void handle(OrderCreatedEvent orderCreatedEvent){
String paymentId = UUID.randomUUID().toString();
System.out.println(“Saga invoked”);
item = orderCreatedEvent.itemType;
//associate Saga
SagaLifecycle.associateWith(“paymentId”, paymentId);
System.out.println(“order id” + orderCreatedEvent.orderId);
//send the commands
commandGateway.send(new CreateInvoiceCommand(paymentId, orderCreatedEvent.orderId));
}
@SagaEventHandler(associationProperty = “paymentId”)
public void handle(InvoiceCreatedEvent invoiceCreatedEvent){
String shippingId = UUID.randomUUID().toString();
System.out.println("Saga continued with " + item);
//associate Saga with shipping
SagaLifecycle.associateWith(“shipping”, shippingId);
//send the create shipping command
commandGateway.send(new CreateShippingCommand(shippingId, invoiceCreatedEvent.orderId, invoiceCreatedEvent.paymentId));
}
The following is my MongoSagaStore configuration
@Configuration
public class SagaServiceConfiguration {
@Bean
public org.axonframework.extensions.mongo.MongoTemplate axonMongoTemplate(org.springframework.data.mongodb.core.MongoTemplate mongoTemplate) {
return DefaultMongoTemplate.builder()
.mongoDatabase(mongoTemplate.getDb())
.trackingTokensCollectionName(“trackingtokens_testsaga”)
.sagasCollectionName(“sagas_test”)
.build();
}
@Bean
public TokenStore mongoTokenStore(org.axonframework.extensions.mongo.MongoTemplate axonMongoTemplate) {
return MongoTokenStore.builder().mongoTemplate(axonMongoTemplate).serializer(JacksonSerializer.defaultSerializer()).build();
}
@Bean
public MongoSagaStore mongoSagaStore(org.axonframework.extensions.mongo.MongoTemplate axonMongoTemplate) {
return MongoSagaStore.builder()
.mongoTemplate(axonMongoTemplate)
.serializer(JacksonSerializer.defaultSerializer())
.build();
}
}
Regards,
Wong Liong Hung