microservices-patterns / ftgo-application

Example code for the book Microservice patterns
Other
3.35k stars 1.29k forks source link

About the unknown exception saga will be in a suspended state. #104

Open isfong opened 3 years ago

isfong commented 3 years ago

In the saga execution process, an exception is intentionally thrown somewhere, and it is not caught. For example, if the input value is not equal to 1, an exception is thrown. At this time, the entire saga will be in a suspended state. It will never be available unless the entire service is restarted.

Continuously initiate operation requests to the saga,the console only output logs:

[nio-8083-exec-5] i.e.t.s.o.SagaInstanceRepositoryJdbc     : Saving com.example.ftgo.orders.application.sagas.cancel.OrderCancelSaga 000001732876e3fb-e0d55e4d5ab20000
[nio-8083-exec-5] i.e.t.s.o.SagaInstanceRepositoryJdbc     : Updating com.example.ftgo.orders.application.sagas.cancel.OrderCancelSaga 000001732876e3fb-e0d55e4d5ab20000

Please help me, I am just a novice.

isfong commented 3 years ago
Although the input value is correct later, no exception will be triggered, but the whole saga is still in a suspended state.
I started saga like this:
 public OrderValue cancel( Long id ) {
        Orders order = this.orderRepository.findById( id )
                .orElseThrow( ( ) -> new OrderNotFoundException( id ) );
        OrderCancelSagaData orderCancelSagaData = new OrderCancelSagaData( order.getConsumerId( ), order.getId( ), order.getOrderTotal( ) );
        this.sagaInstanceFactory.create( this.orderCancelSaga, orderCancelSagaData );
        return order.value( );
}
asn25 commented 3 years ago

Hi,

this may be connected with:

As issue #107 describes, unhandled exception in CommandHandler or in domain service method or in Aggregate method will break the Saga.

In issue #70 an exception "org.springframework.orm.jpa.JpaSystemException: Transaction was marked for rollback only; cannot commit; nested exception is org.hibernate.TransactionException: Transaction was marked for rollback only; cannot commit" breaks not only the current Saga, but all the future Sagas as well. Only full system restart helps.

BTW, what do you mean about suspended state of the Saga, how do you check this state?