Skip to content

Commit

Permalink
Change BPMN
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksander-dytko committed Oct 29, 2024
1 parent 194a500 commit e7f4e26
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 80 deletions.
39 changes: 9 additions & 30 deletions src/main/java/org/example/JobWorkerEL.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

import java.net.URI;
import java.time.Duration;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class JobWorkerEL {
Expand All @@ -32,13 +34,13 @@ private static ZeebeClient createZeebeClient(OAuthCredentialsProvider credential
}

private static void openJobWorkers(ZeebeClient client) {
final String executionListenerType = "endEl";
final String executionListenerType = "startEl";
final String jobWorkerType = "job";

System.out.println("Opening job workers.");

try (JobWorker executionListenerWorker = createJobWorker(client, executionListenerType, new ExecutionListenerHandler());
JobWorker exampleWorker = createJobWorker(client, jobWorkerType, new ExampleJobHandler())) {
try (JobWorker executionListenerWorker = createJobWorker(client, executionListenerType, new ExecutionListenerHandler())){
// ; JobWorker exampleWorker = createJobWorker(client, jobWorkerType, new ExampleJobHandler())) {

System.out.println("Job workers opened and receiving jobs.");
waitUntilSystemInput("exit");
Expand All @@ -63,41 +65,18 @@ private static void waitUntilSystemInput(final String exitCode) {
}
}

public static class Order {
private long orderId;
private double totalPrice;

public long getOrderId() {
return orderId;
}

public void setOrderId(final long orderId) {
this.orderId = orderId;
}

public double getTotalPrice() {
return totalPrice;
}

public void setTotalPrice(final double totalPrice) {
this.totalPrice = totalPrice;
}
}

private static class ExecutionListenerHandler implements JobHandler {
@Override
public void handle(final JobClient client, final ActivatedJob job) {
Order order = job.getVariablesAsType(Order.class);
System.out.println("New job with orderId: " + order.getOrderId() + " for process instance: " + job.getProcessInstanceKey());

GetPrice getPriceInstance = new GetPrice();
getPriceInstance.fetchPrice();
double price = getPriceInstance.getPrice();
System.out.println("New job with creditScore: " + job.getVariable("creditScore") + " for process instance: " + job.getProcessInstanceKey());

System.out.println("The price fetched is: " + price);
order.setTotalPrice(price);
Map<String, Object> variables = new HashMap<>();
variables.put("additionalCheck", true);

client.newCompleteCommand(job.getKey()).variables(order).send().join();
client.newCompleteCommand(job.getKey()).variables(variables).send().join();
}
}

Expand Down
25 changes: 18 additions & 7 deletions src/main/java/org/example/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ public static void main(String[] args) {
.restAddress(URI.create(configLoader.getProperty("ZEEBE_REST_ADDRESS")))
.credentialsProvider(credentialsProvider)
.build()) {
//deployResources(client);
long processInstanceKey = createProcessInstance(client);
correlateOrPublishMessage(client, processInstanceKey);
deployResources(client);

for (int i = 0; i < 5; i++) {
long processInstanceKey = createProcessInstance(client);
correlateOrPublishMessage(client, processInstanceKey);
}
}
}

Expand All @@ -34,29 +37,37 @@ private static void deployResources(ZeebeClient client) {
}

private static long createProcessInstance(ZeebeClient client) {
Map<String, Object> var = new HashMap<>();
var.put("first_name", "Laya");
var.put("last_name", "Williams");
var.put("email", "[email protected]");
var.put("ticketId", "134-31-1679");

var event = client.newCreateInstanceCommand()
.bpmnProcessId("loanOrigination")
.latestVersion()
.send().join();
.variables(var)
.send()
.join();
System.out.println("Process instance created with key: " + event.getProcessInstanceKey());
return event.getProcessInstanceKey();
}

private static void correlateOrPublishMessage(ZeebeClient client, long correlationKey) {
Map<String, Object> variables = new HashMap<>();
variables.put("orderId", correlationKey);
variables.put("creditScore", 760);

try {
long instanceKey = client.newCorrelateMessageCommand()
.messageName("customerInformation")
.correlationKey(String.valueOf(correlationKey))
.correlationKey("134-31-1679")
.variables(variables)
.send().join().getProcessInstanceKey();
System.out.println("Message correlated to instance: " + instanceKey);
} catch (Exception e) {
long messageKey = client.newPublishMessageCommand()
.messageName("customerInformation")
.correlationKey(String.valueOf(correlationKey))
.correlationKey("134-31-1679")
.variables(variables)
.timeToLive(Duration.ofHours(1))
.send().join().getMessageKey();
Expand Down
91 changes: 48 additions & 43 deletions src/main/resources/bank loan origination and processing.bpmn
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
<bpmn:participant id="Participant_0vl257o" name="Customer" />
<bpmn:participant id="Participant_026s99h" name="Bank IT systems" />
<bpmn:participant id="Participant_069kh4a" name="Chatbot" />
<bpmn:messageFlow id="Flow_0zbi9m1" sourceRef="getCreditScore" targetRef="Participant_10cw3k9" />
<bpmn:messageFlow id="Flow_0n8pccj" sourceRef="Participant_10cw3k9" targetRef="getCreditScore" />
<bpmn:messageFlow id="Flow_09zzeg7" sourceRef="Participant_069kh4a" targetRef="loanRequested" />
<bpmn:messageFlow id="Flow_0emvbnh" sourceRef="Activity_0ii025u" targetRef="Participant_0vl257o" />
<bpmn:messageFlow id="Flow_04faq6r" sourceRef="ValidateDataAndCreateTicket" targetRef="Participant_026s99h" />
Expand All @@ -24,6 +22,7 @@
<bpmn:messageFlow id="Flow_0kny3xj" sourceRef="Participant_069kh4a" targetRef="Participant_0vl257o" />
<bpmn:messageFlow id="Flow_1rbcc7e" sourceRef="Participant_0vl257o" targetRef="Participant_069kh4a" />
<bpmn:messageFlow id="Flow_1ntqrd8" sourceRef="Participant_069kh4a" targetRef="Participant_0vl257o" />
<bpmn:messageFlow id="Flow_01nbziz" sourceRef="Participant_10cw3k9" targetRef="Event_1c61boa" />
</bpmn:collaboration>
<bpmn:process id="loanOrigination" name="Bank: Loan origination and processing" isExecutable="true">
<bpmn:sequenceFlow id="Flow_05vdl8x" sourceRef="Event_09ign1n" targetRef="Activity_0ii025u" />
Expand All @@ -33,28 +32,17 @@
<bpmn:sequenceFlow id="Flow_0i2sxpr" sourceRef="Activity_0ehz785" targetRef="Event_1ym330b" />
<bpmn:sequenceFlow id="Flow_0t0fgj1" sourceRef="Activity_0neec1e" targetRef="Event_09ign1n" />
<bpmn:sequenceFlow id="Flow_14mj0nw" sourceRef="Activity_1qx00c8" targetRef="Activity_0ebp42o" />
<bpmn:sequenceFlow id="Flow_1myqvj5" sourceRef="loanRequested" targetRef="getCreditScore" />
<bpmn:sequenceFlow id="Flow_1nyx4yp" sourceRef="Event_1ym330b" targetRef="Activity_1qx00c8" />
<bpmn:sequenceFlow id="Flow_1q8k0ac" sourceRef="Activity_0ebp42o" targetRef="Event_0p71g2v" />
<bpmn:sequenceFlow id="Flow_1ythlix" sourceRef="Event_0oxv702" targetRef="Event_1pq5rfu" />
<bpmn:serviceTask id="getCreditScore" name="Get credit score">
<bpmn:extensionElements>
<zeebe:taskDefinition type="job" />
<zeebe:properties>
<zeebe:property name="camundaModeler:exampleOutputJson" value="{&#10; &#34;creditScore&#34;: 760,&#10; &#34;ticketId&#34;: 123&#10;}" />
</zeebe:properties>
</bpmn:extensionElements>
<bpmn:incoming>Flow_1myqvj5</bpmn:incoming>
<bpmn:outgoing>Flow_1k7rao8</bpmn:outgoing>
</bpmn:serviceTask>
<bpmn:startEvent id="loanRequested" name="loan requested">
<bpmn:extensionElements>
<zeebe:formDefinition formId="Form_16l6p9i" />
<zeebe:properties>
<zeebe:property name="camundaModeler:exampleOutputJson" value="{&#10; &#34;address&#34;: {&#10; &#34;first_name&#34;: &#34;Laya&#34;,&#10; &#34;last_name&#34;: &#34;Williams&#34;,&#10; &#34;address_1&#34;: &#34;123 Anywhere Dr&#34;,&#10; &#34;address_2&#34;: &#34;&#34;,&#10; &#34;city&#34;: &#34;Raleigh&#34;,&#10; &#34;zip_code&#34;: &#34;27697&#34;,&#10; &#34;state&#34;: &#34;North Carolina&#34;,&#10; &#34;country&#34;: &#34;USA&#34;&#10; },&#10; &#34;contact&#34;: {&#10; &#34;email&#34;: &#34;[email protected]&#34;,&#10; &#34;phone&#34;: &#34;+4930664040900&#34;,&#10; &#34;mobile&#34;: &#34;+4930664040900&#34;&#10; },&#10; &#34;pi&#34;: {&#10; &#34;ssn&#34;: &#34;134-31-1679&#34;,&#10; &#34;date_of_birth&#34;: null,&#10; &#34;annual_salary&#34;: 55200,&#10; &#34;current_employer&#34;: &#34;Styles and Speed Printing LLC.&#34;&#10; },&#10; &#34;loan&#34;: {&#10; &#34;amount&#34;: 25000,&#10; &#34;tenure&#34;: 36&#10; }&#10;}" />
</zeebe:properties>
</bpmn:extensionElements>
<bpmn:outgoing>Flow_1myqvj5</bpmn:outgoing>
<bpmn:outgoing>Flow_145cnel</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:sequenceFlow id="Flow_1uqps3a" name="Yes" sourceRef="Gateway_0h8t0o8" targetRef="ValidateDataAndCreateTicket">
<bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">=additionalCheck = false</bpmn:conditionExpression>
Expand Down Expand Up @@ -273,8 +261,13 @@
</bpmn:timerEventDefinition>
</bpmn:boundaryEvent>
<bpmn:exclusiveGateway id="Gateway_0odman6" name="Do we need more data?">
<bpmn:extensionElements>
<zeebe:executionListeners>
<zeebe:executionListener eventType="start" type="startEl" />
</zeebe:executionListeners>
</bpmn:extensionElements>
<bpmn:incoming>Flow_12o7iz6</bpmn:incoming>
<bpmn:incoming>Flow_1k7rao8</bpmn:incoming>
<bpmn:incoming>Flow_1rybhfo</bpmn:incoming>
<bpmn:outgoing>Flow_0gr6q5q</bpmn:outgoing>
<bpmn:outgoing>Flow_1tykdw0</bpmn:outgoing>
</bpmn:exclusiveGateway>
Expand All @@ -289,16 +282,11 @@
</bpmn:sequenceFlow>
<bpmn:sequenceFlow id="Flow_1r4dbfu" sourceRef="customerInformationReceived" targetRef="Gateway_1i87sao" />
<bpmn:sequenceFlow id="Flow_1t0w6hs" sourceRef="ValidateDataAndCreateTicket" targetRef="Activity_0ehz785" />
<bpmn:sequenceFlow id="Flow_1k7rao8" sourceRef="getCreditScore" targetRef="Gateway_0odman6" />
<bpmn:sequenceFlow id="Flow_1kp5g1n" sourceRef="Gateway_1i87sao" targetRef="Gateway_0h8t0o8" />
<bpmn:serviceTask id="ValidateDataAndCreateTicket" name="Validate data and create ticket">
<bpmn:extensionElements>
<zeebe:taskDefinition type="job" />
<zeebe:properties />
<zeebe:executionListeners>
<zeebe:executionListener eventType="start" type="startEl" />
<zeebe:executionListener eventType="end" type="endEl" />
</zeebe:executionListeners>
</bpmn:extensionElements>
<bpmn:incoming>Flow_1uqps3a</bpmn:incoming>
<bpmn:outgoing>Flow_1t0w6hs</bpmn:outgoing>
Expand All @@ -319,13 +307,32 @@
<bpmn:outgoing>Flow_12o7iz6</bpmn:outgoing>
</bpmn:exclusiveGateway>
<bpmn:sequenceFlow id="Flow_0vnblrd" sourceRef="missingInformationRequest" targetRef="customerInformationReceived" />
<bpmn:serviceTask id="missingInformationRequest" name="Request missing information from the customer">
<bpmn:serviceTask id="missingInformationRequest" name="Request missing information from the customer" zeebe:modelerTemplate="io.camunda.connectors.HttpJson.v2" zeebe:modelerTemplateVersion="8" zeebe:modelerTemplateIcon="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTgiIGhlaWdodD0iMTgiIHZpZXdCb3g9IjAgMCAxOCAxOCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZD0iTTE3LjAzMzUgOC45OTk5N0MxNy4wMzM1IDEzLjQ0NzUgMTMuNDI4MSAxNy4wNTI5IDguOTgwNjUgMTcuMDUyOUM0LjUzMzE2IDE3LjA1MjkgMC45Mjc3NjUgMTMuNDQ3NSAwLjkyNzc2NSA4Ljk5OTk3QzAuOTI3NzY1IDQuNTUyNDggNC41MzMxNiAwLjk0NzA4MyA4Ljk4MDY1IDAuOTQ3MDgzQzEzLjQyODEgMC45NDcwODMgMTcuMDMzNSA0LjU1MjQ4IDE3LjAzMzUgOC45OTk5N1oiIGZpbGw9IiM1MDU1NjIiLz4KPHBhdGggZD0iTTQuOTMxMjYgMTQuMTU3MUw2Ljc4MTA2IDMuNzE0NzFIMTAuMTM3NUMxMS4xOTE3IDMuNzE0NzEgMTEuOTgyNCAzLjk4MzIzIDEyLjUwOTUgNC41MjAyN0MxMy4wNDY1IDUuMDQ3MzYgMTMuMzE1IDUuNzMzNTggMTMuMzE1IDYuNTc4OTJDMTMuMzE1IDcuNDQ0MTQgMTMuMDcxNCA4LjE1NTIyIDEyLjU4NDEgOC43MTIxNUMxMi4xMDY3IDkuMjU5MTMgMTEuNDU1MyA5LjYzNzA1IDEwLjYyOTggOS44NDU5TDEyLjA2MTkgMTQuMTU3MUgxMC4zMzE1TDkuMDMzNjQgMTAuMDI0OUg3LjI0MzUxTDYuNTEyNTQgMTQuMTU3MUg0LjkzMTI2Wk03LjQ5NzExIDguNTkyODFIOS4yNDI0OEM5Ljk5ODMyIDguNTkyODEgMTAuNTkwMSA4LjQyMzc0IDExLjAxNzcgOC4wODU2MUMxMS40NTUzIDcuNzM3NTMgMTEuNjc0MSA3LjI2NTEzIDExLjY3NDEgNi42Njg0MkMxMS42NzQxIDYuMTkxMDYgMTEuNTI0OSA1LjgxODExIDExLjIyNjUgNS41NDk1OUMxMC45MjgyIDUuMjcxMTMgMTAuNDU1OCA1LjEzMTkgOS44MDkzNiA1LjEzMTlIOC4xMDg3NEw3LjQ5NzExIDguNTkyODFaIiBmaWxsPSJ3aGl0ZSIvPgo8L3N2Zz4K">
<bpmn:extensionElements>
<zeebe:taskDefinition type="job" />
<zeebe:taskDefinition type="io.camunda:http-json:1" retries="3" />
<zeebe:ioMapping>
<zeebe:input source="noAuth" target="authentication.type" />
<zeebe:input source="GET" target="method" />
<zeebe:input source="https://635684e19243cf412f86c4ec.mockapi.io/api/v1/totalPrice/1" target="url" />
<zeebe:input source="20" target="connectionTimeoutInSeconds" />
<zeebe:input source="20" target="readTimeoutInSeconds" />
</zeebe:ioMapping>
<zeebe:taskHeaders>
<zeebe:header key="resultExpression" value="=body" />
<zeebe:header key="retryBackoff" value="PT0S" />
</zeebe:taskHeaders>
</bpmn:extensionElements>
<bpmn:incoming>Flow_1tykdw0</bpmn:incoming>
<bpmn:outgoing>Flow_0vnblrd</bpmn:outgoing>
</bpmn:serviceTask>
<bpmn:sequenceFlow id="Flow_1rybhfo" sourceRef="Event_1c61boa" targetRef="Gateway_0odman6" />
<bpmn:sequenceFlow id="Flow_145cnel" sourceRef="loanRequested" targetRef="Event_1c61boa" />
<bpmn:intermediateCatchEvent id="Event_1c61boa" name="Get credit score">
<bpmn:extensionElements />
<bpmn:incoming>Flow_145cnel</bpmn:incoming>
<bpmn:outgoing>Flow_1rybhfo</bpmn:outgoing>
<bpmn:messageEventDefinition id="MessageEventDefinition_11lms9u" messageRef="Message_3m04392" />
</bpmn:intermediateCatchEvent>
</bpmn:process>
<bpmn:message id="Message_02eoed2" name="customer_accepts_offer">
<bpmn:extensionElements>
Expand All @@ -343,10 +350,6 @@
<dc:Bounds x="160" y="260" width="1840" height="450" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="BPMNShape_1o8jedc" bpmnElement="getCreditScore">
<dc:Bounds x="310" y="300" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="loanRequested">
<dc:Bounds x="232" y="322" width="36" height="36" />
<bpmndi:BPMNLabel>
Expand Down Expand Up @@ -403,6 +406,12 @@
<bpmndi:BPMNShape id="Activity_0j6fkc3_di" bpmnElement="missingInformationRequest">
<dc:Bounds x="510" y="410" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_1rqfjrt_di" bpmnElement="Event_1c61boa">
<dc:Bounds x="332" y="322" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="311" y="298" width="78" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1p1ub97_di" bpmnElement="Activity_0ehz785">
<dc:Bounds x="960" y="300" width="100" height="80" />
<bpmndi:BPMNLabel />
Expand Down Expand Up @@ -512,10 +521,6 @@
<di:waypoint x="1310" y="340" />
<di:waypoint x="1350" y="340" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1myqvj5_di" bpmnElement="Flow_1myqvj5">
<di:waypoint x="268" y="340" />
<di:waypoint x="310" y="340" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1nyx4yp_di" bpmnElement="Flow_1nyx4yp">
<di:waypoint x="1168" y="340" />
<di:waypoint x="1210" y="340" />
Expand Down Expand Up @@ -568,10 +573,6 @@
<di:waypoint x="940" y="340" />
<di:waypoint x="960" y="340" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1k7rao8_di" bpmnElement="Flow_1k7rao8">
<di:waypoint x="410" y="340" />
<di:waypoint x="465" y="340" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1kp5g1n_di" bpmnElement="Flow_1kp5g1n">
<di:waypoint x="695" y="340" />
<di:waypoint x="725" y="340" />
Expand All @@ -580,6 +581,14 @@
<di:waypoint x="610" y="450" />
<di:waypoint x="652" y="450" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1rybhfo_di" bpmnElement="Flow_1rybhfo">
<di:waypoint x="368" y="340" />
<di:waypoint x="465" y="340" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_145cnel_di" bpmnElement="Flow_145cnel">
<di:waypoint x="268" y="340" />
<di:waypoint x="332" y="340" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="Participant_1vxij6s_di" bpmnElement="Participant_10cw3k9" isHorizontal="true">
<dc:Bounds x="160" y="740" width="300" height="60" />
<bpmndi:BPMNLabel />
Expand All @@ -596,14 +605,6 @@
<dc:Bounds x="160" y="170" width="900" height="60" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Flow_0zbi9m1_di" bpmnElement="Flow_0zbi9m1">
<di:waypoint x="340" y="380" />
<di:waypoint x="340" y="740" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0n8pccj_di" bpmnElement="Flow_0n8pccj">
<di:waypoint x="380" y="740" />
<di:waypoint x="380" y="380" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_09zzeg7_di" bpmnElement="Flow_09zzeg7">
<di:waypoint x="250" y="230" />
<di:waypoint x="250" y="322" />
Expand Down Expand Up @@ -666,6 +667,10 @@
<di:waypoint x="650" y="170" />
<di:waypoint x="650" y="140" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_01nbziz_di" bpmnElement="Flow_01nbziz">
<di:waypoint x="350" y="740" />
<di:waypoint x="350" y="358" />
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
<bpmndi:BPMNDiagram id="BPMNDiagram_0h2934k">
Expand Down Expand Up @@ -841,4 +846,4 @@
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
</bpmn:definitions>

0 comments on commit e7f4e26

Please sign in to comment.