Skip to content

dobrynya/saga

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple Saga pattern implementation

This code provides sample decision to coordinate complex non-transactional processes and roll back different parts in case of any failure.

Consider the following case: a system would like to send an invoice to a client.

import shapeless.HNil
import ru.dimitrius.SagaBuilder.saga

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")
}

About

Just a Saga Pattern implementation

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages