Creating SagaSerializable Class for Aggregator
Providing sample objects for the framework is very important to capture the feature failures that can be occurred due to the version updates of the Aggregator. You can have a better understanding of version updates through the following topics.
Let’s look at the implementation of SagaSerializable
here:
The SagaSerializable
class provides you a method called <T> getSamples()
to provide the sample array of objects of your real Aggregator. for each aggregator class that you made should have a separate implementation of SagaSerializable
for validating the sample object before the application is started. that process ensures that your aggregator object will not face a serialization error while the transactions are being processed in the production.
you can see a sample SagaSerializable (PlaceOrderAggregatorSample.class)
implementation of the PlaceOrderAggregator.
public class PlaceOrderAggregatorSample extends SagaSerializable<PlaceOrderAggregator> { (1)
public PlaceOrderAggregatorSample() {
//sample-1
PlaceOrderAggregator aggregator1 = new PlaceOrderAggregator();
aggregator1.setOrderId(UUID.randomUUID().toString());
this.put("1", aggregator1);(2)
//sample-2
PlaceOrderAggregator aggregator2 = new PlaceOrderAggregator();
aggregator2.setOrderId(UUID.randomUUID().toString());
aggregator2.setUsername("mafei");
this.put("2", aggregator2);(2)
//sample-3
PlaceOrderAggregator aggregator3 = new PlaceOrderAggregator();
aggregator3.getItemDetails().add(
PlaceOrderAggregator.ItemDetail
.builder()
.itemName("Item-01")
.price(10.50)
.qty(2)
.build()
);
this.put("3", aggregator3); (2)
}
}
1 | Implement your custom PlaceOrderAggregatorSample from the SagaSerializable<T> .
The generic type should be the aggregator that you wish to check the sample object.
According to the example, the Type is PlaceOrderAggregator .
Then you will have a method for providing the sample objects for that given type. |
2 | Put your initialized sample objects for the validation process by using put(key,vlaue) method.
The key should be unique for each.
And also you have to provide at least one sample object. |
Make sure to keep the default constructor for each SagaSerializable implementation. |