WORK IN PROGRESS this is an intermediate version please do not distribute. Best Practices Data in processes
Online Arbeitsgruppe Best Practices Erarbeitung von Best Practices Thema für Thema Ziele Beschreibung der Alternativen Entscheidungskriterien & Empfehlungen Namesfindung / Einigung auf Wording Heute: Daten in Prozessen (2. Termin) Aufruf: Eigenes Material & Beispiele mitbringen! Hat jemand etwas dabei? Keine Frontbeschallung! Sorry für deutsch/englisch.
Was uns interessiert Feedback und Anregungen Vollständigkeit der Use Cases & Empirie Was ist hilfreich für euch? Welche Form der Aufbereitung könnt ihr euch vorstellen? Patterns und Ideen
Intro Order - id - customer - items -
Processes and Data Classification What kind of data could you store in the process? Reference (e.g. id of customer, order, document, ) Payload (e.g. data flow centric processes or message correlation scenarios, SOA?; user task input for later service call -> delete after use) Decision (e.g. approved) if they are not part of the domain model and only necessary for the process flow. Are decisions Payload? Temporary Copy (e.g. you want to save a service result to be independent of changes in that system during some phase in the process; e.g. data from an expensive/slow external service might be cached in the process context) Documents (e.g. documents as binary data linked to a process instance) Merker: + SomeData - attribute 1 - attribute 2 - - Abgrenzung transiente Prozessvariablen - Wie kann Decision entfernt werden nach Gateway (beim verlassen des Gateway per Listener)
Processes and Data Storage How to store data in camunda BPM: Business Key: The business key is one string per process instance used to link it to exactly one domain entity/key. Process Variables (built-in capability of process engine; provided via HashMap like interface; key/values pairs). Value is stored: primitive types in own column complex types, will be serialized (see Serialization) External Data: Data can be stored outside of the process engine scope and retrieved when necessary via API or Service Call; the link is maintained via reference as process variable. Note that declared BPMN data objects according to the specification are not supported, because the HashMap approach is sufficient for real-life use cases. Everything missing can be implemented easily using Patterns. + SomeData - attribute 1 - attribute 2 -
Processes and Data Serialization Serialization of Process Variables can be influenced: Built-In byte code serialization or String (XML/JSON) serialization (planned) JPA Entities can be used to store data. They can be put in the same database schema as the process engine. The link can be maintained automatically. Currently not JPA2 and very limited not recommended. Better maintain yourself with Pattern. Client Serialization: Serialize data yourself into a String before adding as process variable (primitive type String), see Pattern. client serialization Engine Serialization: Hook in own VariableType to influence Serialization in the Process Engine (gets called whenever a process variable is loaded or stored) ENGINE Engine serialization
BPMN Data Objects camunda BPM does not support of BPMN data objects! We use the Map approach instead (more flexible, less boiler plate code) However: You can still draw them for documentation purposes Discussion on it postponed to later
Storage Wie korreliert das zu Data Types? Process Variable JPA Entity External Data (Reference and Service Call) VARIABLE orderid 19 VARIABLE VARIABLE ORDER var1 Var2 value1 18 orderid 19 19 20 Scope Process ORDER 19 20 Scope Process Scope Process Scope Data Process Engine Tables Process Engine Tables Entity Tables Process Engine Tables Entity Tables
Empfehlungen und Gedanken Referenzen bevorzugen Ob Entity oder Extern hängt an der Architektur Payload OK wenn nachrichtenbasiert Entscheidungen OK als Prozessvariablen Achtung: Sind nicht im Domänenmodell vorhanden Möglichst wenig Daten im Prozess!
Processes and Data Pattern Proposal: Problem Solution Zugriff auf EINE Variable ProcessVariableAc cessor
Processes and Data Pattern Proposal: ProcessDataAccessor @Named ProcessData Problem Process Variables are not declared and referenced simply by name (String). This gives no security against typos. Type conversion (casting) has to be done all over the application. Solution Introduce a ProcessDataBean as central accessor to all process variables. It knows the name and type of all process variables. The ProcessDataBean can do any necessary type conversions. When using CDI this can be implemented very elegant. + getvar1() + setvar1(value) +
Processes and Data Example using CDI Pattern Proposal: ProcessDataAccesor @Named ProcessData + getvar1() + setvar1(value) + Problem Lokale Variablen in CDI Beispiele für Plain Java Zweiter Construct mit Map/Mock/VariableScope Evtl. Komposite von ProcessVariableAccessor
Processes and Data Pattern Proposal: ProcessDataBean Use when? Big project (many process variables, many usages, many developers, ) Client Serialization is used to do data mapping Usage examples TODO: Should be contained in an example or quickstart @Named ProcessData + getvar1() + setvar1(value) +
Processes and Data Pattern Proposal: ProcessVariableProduc er ProcessVariableRefere nceresolver Problem External Data has to be queried within the process (e.g. in Gateway, ServiceTask, ). This results in bloated code to load the data and in requirements to cache this. Solution Use a CDI Producer to load the data transparently. CDI scopes take care of caching. Works with JPA but also with external services. Evtl. ProcessVariableAccessor um die Referenz zu holen Getrenntes Pattern da sonst zu viel in einem. Spezialisierung von ProcessVariableAccessor Implementierung in Spring?
Offene Punkte Validierung von Daten, Validierungsfehler, TX Transiente Prozessvariablen Audit Log für Variablenänderungen Global and local variables Classloading with SharedProcessEngine Examples Gateway mit Entscheidungslogik über Daten aus Serviceaufruf davor - Transiente Variablen? Transaktionsgrenzen beachten! - Temporäre Decision als Process Variables / wann löschen? - Default Flow verwenden? Liste für MI laden wie serialisieren? Custom Queries in Tasklist
Feedback: I like Gut gewisse Dinge festzuzurren um es im Projekt nicht immer anders zu machen; Namensdiskussion lange aber hilfreich. Viele Teilnehmer + aktive Diskussion
Feedback: I whish Sprechen Spring Best Practices als Ergebnis aus den Webinaren auf camunda.org fände ich auch toll Besser Zielgruppe-Beschreibung (Java, technisch, camunda BPM wenig BPMN) Regelmäßig alle 4 Wochen Diskussion über Forum Thema: Braucht man Data Objects in camunda BPM?