Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Workflow engines with Clojure - It's a match!

Tim Zöller
February 23, 2019

Workflow engines with Clojure - It's a match!

With digital processes becoming more complex every year, and the digitalization finally arriving in our companies, workflow engines become more popular in the Java ecosystem. Describing process flows as a graphic model in BPMN (Business Process Model and Notation) makes them readable and enables workflow tools to execute them. When we let these engines keep the state and orchestrate the steps of a process, we gain the possibility to split our software into atomic delegates. We will explore together, how we can integrate a Java BPM engine with Clojure and how both form a love relationship which makes development incredibly fun and rewarding for us.

Tim Zöller

February 23, 2019
Tweet

More Decks by Tim Zöller

Other Decks in Technology

Transcript

  1. 16 Deploy a Process Definition (defn deploy-process [definition-file] (let [repo-service

    (.getRepositoryService camunda) name "ServiceDesk.bpmn" input-stream (clojure.java.io/input-stream definition-file)] (.deploy (.addInputStream (.createDeployment repo-service) name input-stream)))) (deploy-process “/my/path/ServiceDesk.bpmn")
  2. 17 Start a Process Instance (defn start-instance-by-key [key variables] (.startProcessInstanceByKey

    (.getRuntimeService camunda) key variables)) (start-instance-by-key "service-desk" {"service-type" "premium" "customer-no" "12345"})
  3. 23 How is it done in Java? @Named("mailDelegate") public class

    MailDelegate implements JavaDelegate { @Inject private MailSender mailSender; @Override public void execute(DelegateExecution execution) throws Exception { String lastName = (String) execution.getVariable("firstName"); String firstName = (String) execution.getVariable("lastName"); String emailAddress = (String) execution.getVariable("mailAddress"); mailSender.sendLowPrioMail(firstName, lastName, emailAddress); } } MEH
  4. 24 What about Clojure? (ns engine-clojure.mail-delegate (:gen-class :name de.javahippie.camunda.MailDelegate :implements

    [org.camunda.bpm.engine.delegate.JavaDelegate]) (:require [my-mailer :as mailer])) (defn -execute [this execution] (let [{firstName "firstName" lastName "lastName" eMail "mailAddress"} (.getVariables execution)] (mailer/send firstName lastName eMail)))
  5. 28 Wrap the TASK Service (defn get-tasks-for-candidate-group [group] (map convert-task

    (.list (.taskCandidateGroup (.createTaskQuery (task-service)) group)))) (defn claim-task [id user] (.claim (task-service) id user)) (defn get-task-variables [id] (into {} (.getVariables (task-service) id))) (defn complete-task [id variables] (.complete (task-service) id variables))
  6. 36

  7. Recommended: Camunda User Group Berlin Camunda and Clojure Hans Hübner

    & Robert Peckett LambadaWerk https://www.meetup.com/de- DE/Camunda-User-Group-Berlin/ 26 37
  8. TIM Zöller Senior IT Consultant ilum:e informatik ag in Mainz

    Living in Freiburg Developing Java applications since 2008 Co-Founder of JUG Mainz Profiles About me JVM 90 % Web 70 % Music 100 % communication 90 % … so, who am i? 38 javahippie @javahippie Tim Zöller