Implement workers for external tasks in Camunda BPM in Scala, based on Akka.
Alternative Versions:
This tool provides a Scala template to external tasks exposed by the process engine. You can build a scala worker based on the template.
Requirements
- SBT to build the application
Test the application local with
sbt "test:runMain org.camunda.worker.akka.Main"
Build the application with
sbt assembly
Deploy the application with
sbt publishLocal
See example of using the akka worker in Order Processing Microservices example.
Write a launch class:
object Main extends App {
// create actor system
val system = ActorSystem("MyActorSystem")
// create worker
val worker = system.actorOf(Props[PaymentWorker], name = "payment-worker")
// start polling
val pollActor = system.actorOf(PollActor.props(hostAddress = "http://localhost:8080/engine-rest", maxTasks = 5, waitTime= 100, lockTime = 600))
pollActor ! Poll(topicName = "payment", worker, variableNames = List("order"))
}
Write a worker:
class PaymentWorker extends Worker {
def work(task: LockedTask): Map[String, VariableValue] = {
// resolve variables from process instance
val orderId: String = task.variable[JValue]("order") match {
case Some(json) => (json \ "orderId").extract[String]
case None => throw new IllegalArgumentException("order is not available")
}
// do the work
val payment = calculatePayment(orderId)
// return the result which will set as variable of the process instance
Map("payment" -> payment)
}
}