Skip to main content

ZIO Temporal

Build invincible apps with ZIO and Temporal

Convenient

Working with Temporal is natural as though it was developed for Scala

Robust

The library handles most typical programmer errors at compile time.

No more dumb runtime exceptions!

ZIO-native

Use your favorite ZIO library with Temporal!

Running ZIO code inside your workflows has never been that easy!

Get started easily

Here is an example of how simple it is to run and interact with Temporal workflows.


import zio._
import zio.temporal._
import zio.temporal.workflow._
import zio.temporal.protobuf.syntax._

// Business process as an interface
@workflowInterface
trait PaymentWorkflow {

@workflowMethod
def proceed(transaction: ProceedTransactionCommand): TransactionView

@queryMethod
def isFinished(): Boolean

@signalMethod
def confirmTransaction(command: ConfirmTransactionCommand): Unit
}

// Client-side code
class TemporalPaymentService(workflowClient: ZWorkflowClient) {
def createPayment(sender: UUID, receiver: UUID, amount: BigDecimal) =
for {
transactionId <- ZIO.randomWith(_.nextUUID)
paymentWorkflow <- workflowClient.newWorkflowStub[PaymentWorkflow](
ZWorkflowOptions
.withWorkflowId(transactionId.toString)
.withTaskQueue("payments")
// Built-in timeouts
.withWorkflowExecutionTimeout(6.minutes)
.withWorkflowRunTimeout(1.minute)
// Built-in retries
.withRetryOptions(
ZRetryOptions.default.withMaximumAttempts(5)
)
)
// Start the business process
_ <- ZWorkflowStub.start(
paymentWorkflow.proceed(
ProceedTransactionCommand(
id = transactionId,
sender = sender,
receiver = receiver,
amount = amount
)
)
)
} yield transactionId

def confirmTransaction(transactionId: UUID, confirmationCode: String) =
for {
// Get the running business process
workflowStub <- workflowClient.newWorkflowStub[PaymentWorkflow](
workflowId = transactionId.toString
)
// Check the business process state
isFinished <- ZWorkflowStub.query(
workflowStub.isFinished()
)
_ <- ZIO.unless(isFinished) {
// Interact with a running workflow!
ZWorkflowStub.signal(
workflowStub.confirmTransaction(
ConfirmTransactionCommand(id = transactionId, confirmationCode)
)
)
}
} yield ()
}