The saga patten is quite simple, if call is failed, the compensation method
should be called.
I know someone already provide the framework[1] with Scala to simplify the
complex if else check.
The PersonService and EmailService can be the remote service or local
service.

val persistInvoiceAndSendEmail: Future[Email :: Person :: HNil] = saga
  .part[Person](PersonService.addInvoice(person, invoice), p =>
PersonService.deleteInvoice(p, invoice))
  .part[Email](EmailService.sendInvoice(person.email, invoice), letter
=> EmailService.sendExcuse(letter.email,
EmailService.createExcuse(letter)))
  .run

persistInvoiceAndSendEmail.onComplete {
  case Success(email :: person :: HNil) =>
    logger.debug("There you can manage process results")
  case Failure(SagaFailed(message, _)) =>
    logger.error(s"One saga part has been failed due to $message")
}



[1]https://github.com/dobrynya/saga


Willem Jiang

Twitter: willemjiang
Weibo: 姜宁willem

On Mon, Aug 20, 2018 at 10:26 PM, Zheng Feng <[email protected]> wrote:

> Thanks Willem and it is a good point here. Also I'm interesting how it
> could be used in the local or the embedded interface ? I wonder if you can
> consider the ACID transaction in this situation.
> The Saga in my options could be more used for the distributed environment.
>
> Regard,
> Amos
>
> 2018-08-20 18:00 GMT+08:00 Willem Jiang <[email protected]>:
>
> > the saga-core has a transport[1] interface which could be used for the
> > purpose, now it just have the Restful implementation.
> > If you want to implement a RPC or some local method, you can just
> implement
> > the transport interface.
> > As the saga-core using json for the invocation, you need to updated the
> > request/response  json module[2] there.
> >
> > [1]
> > https://github.com/apache/incubator-servicecomb-saga/
> > blob/master/saga-core/src/main/java/org/apache/servicecomb/saga/core/
> > Transport.java#L20:18
> > [2]
> > https://github.com/apache/incubator-servicecomb-saga/
> > tree/master/saga-format
> >
> >
> >
> > Willem Jiang
> >
> > Twitter: willemjiang
> > Weibo: 姜宁willem
> >
> > On Mon, Aug 20, 2018 at 5:37 PM, 新道场开张了 <[email protected]> wrote:
> >
> > > Hi, all:
> > >
> > >
> > > Currently, service comb saga have implemented transaction management
> > based
> > > on microservice.
> > > But in some cases, users want to use Saga with a simpler way, such as
> > > local or embedded call.
> > > So we want to discuss whether it is possible to extend a local or
> > embedded
> > > interface.
> > > When the user implements the embedded interface and injects Saga into
> the
> > > native program,
> > > Saga calls the local method directly instead of calling the
> microservice.
> > >
> > >
> > > Best Wishes & Regards
> >
>

Reply via email to