Skip to content

Commit

Permalink
Adjusted code and bpmn for the demo
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksander-dytko committed Oct 30, 2024
1 parent b98c44a commit bad3426
Show file tree
Hide file tree
Showing 5 changed files with 487 additions and 115 deletions.
65 changes: 0 additions & 65 deletions src/main/java/org/example/GetPrice.java

This file was deleted.

27 changes: 14 additions & 13 deletions src/main/java/org/example/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ public static void main(String[] args) {
deployResources(client);

for (int i = 0; i < 5; i++) {
long processInstanceKey = createProcessInstance(client);
correlateOrPublishMessage(client, processInstanceKey);
createProcessInstance(client, i);
for (int k = 0; k < 2; k++) {
correlateOrPublishMessage(client, i);
}
}
}
}
Expand All @@ -33,45 +35,44 @@ private static void deployResources(ZeebeClient client) {
.addResourceFromClasspath("loan application form.form")
.addResourceFromClasspath("loan underwriting form.form")
.send().join().getKey();
System.out.println("Deployed process definition with key: " + deploymentKey);
System.out.println("Deployed process resources with key: " + deploymentKey);
}

private static long createProcessInstance(ZeebeClient client) {
private static void createProcessInstance(ZeebeClient client, Integer i) {
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.put("email", "[email protected]");
var.put("ticketId", "A-"+i.toString());

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

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

try {
long instanceKey = client.newCorrelateMessageCommand()
.messageName("customerInformation")
.correlationKey("134-31-1679")
.correlationKey("A-"+correlationKey.toString())
.variables(variables)
.send().join().getProcessInstanceKey();
System.out.println("Message correlated to instance: " + instanceKey);
System.out.println(correlationKey+". Message correlated to instance: " + instanceKey);
} catch (Exception e) {
long messageKey = client.newPublishMessageCommand()
.messageName("customerInformation")
.correlationKey("134-31-1679")
.correlationKey("A-"+correlationKey.toString())
.variables(variables)
.timeToLive(Duration.ofHours(1))
.send().join().getMessageKey();
System.out.println("Message published with key: " + messageKey);
System.out.println(correlationKey+". Message published with key: " + messageKey);
}
}
}
67 changes: 30 additions & 37 deletions src/main/resources/bank loan origination and processing.bpmn
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:zeebe="http://camunda.org/schema/zeebe/1.0" xmlns:modeler="http://camunda.org/schema/modeler/1.0" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Web Modeler" exporterVersion="1110f25" modeler:executionPlatform="Camunda Cloud" modeler:executionPlatformVersion="8.6.0" camunda:diagramRelationId="9b349217-aad8-4473-b017-e01d5a54650f">
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:zeebe="http://camunda.org/schema/zeebe/1.0" xmlns:modeler="http://camunda.org/schema/modeler/1.0" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.28.0" modeler:executionPlatform="Camunda Cloud" modeler:executionPlatformVersion="8.6.0" camunda:diagramRelationId="9b349217-aad8-4473-b017-e01d5a54650f">
<bpmn:error id="Error_1waf4p2" name="loan declined" errorCode="loan_declined" />
<bpmn:collaboration id="Collaboration_14g551t">
<bpmn:participant id="Participant_0ql02t4" name="Bank: Loan Origination and Processing" processRef="loanOrigination" />
Expand Down Expand Up @@ -261,6 +261,7 @@
</bpmn:timerEventDefinition>
</bpmn:boundaryEvent>
<bpmn:exclusiveGateway id="Gateway_0odman6" name="Do we need more data?">
<bpmn:documentation>Start EL (jobType: "startEl") for gateway to check if we need more data</bpmn:documentation>
<bpmn:extensionElements>
<zeebe:executionListeners>
<zeebe:executionListener eventType="start" type="startEl" />
Expand All @@ -277,7 +278,7 @@
<bpmn:sequenceFlow id="Flow_0gr6q5q" name="No" sourceRef="Gateway_0odman6" targetRef="Gateway_1i87sao">
<bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">=additionalCheck = false</bpmn:conditionExpression>
</bpmn:sequenceFlow>
<bpmn:sequenceFlow id="Flow_1tykdw0" name="Yes" sourceRef="Gateway_0odman6" targetRef="missingInformationRequest">
<bpmn:sequenceFlow id="Flow_1tykdw0" name="Yes" sourceRef="Gateway_0odman6" targetRef="Activity_099dv3b">
<bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">=additionalCheck = true</bpmn:conditionExpression>
</bpmn:sequenceFlow>
<bpmn:sequenceFlow id="Flow_1r4dbfu" sourceRef="customerInformationReceived" targetRef="Gateway_1i87sao" />
Expand All @@ -296,17 +297,11 @@
<bpmn:incoming>Flow_1r4dbfu</bpmn:incoming>
<bpmn:outgoing>Flow_1kp5g1n</bpmn:outgoing>
</bpmn:exclusiveGateway>
<bpmn:intermediateCatchEvent id="customerInformationReceived" name="Customer information received">
<bpmn:incoming>Flow_0vnblrd</bpmn:incoming>
<bpmn:outgoing>Flow_1r4dbfu</bpmn:outgoing>
<bpmn:messageEventDefinition id="MessageEventDefinition_0wbei0k" messageRef="Message_3m04392" />
</bpmn:intermediateCatchEvent>
<bpmn:exclusiveGateway id="Gateway_0h8t0o8" name="Enough data?">
<bpmn:incoming>Flow_1kp5g1n</bpmn:incoming>
<bpmn:outgoing>Flow_1uqps3a</bpmn:outgoing>
<bpmn:outgoing>Flow_12o7iz6</bpmn:outgoing>
</bpmn:exclusiveGateway>
<bpmn:sequenceFlow id="Flow_0vnblrd" sourceRef="missingInformationRequest" targetRef="customerInformationReceived" />
<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">
Expand All @@ -315,23 +310,23 @@
<bpmn:outgoing>Flow_1rybhfo</bpmn:outgoing>
<bpmn:messageEventDefinition id="MessageEventDefinition_11lms9u" messageRef="Message_3m04392" />
</bpmn:intermediateCatchEvent>
<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:intermediateCatchEvent id="customerInformationReceived" name="Customer information received">
<bpmn:extensionElements>
<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:output source="=false" target="additionalCheck" />
</zeebe:ioMapping>
<zeebe:taskHeaders>
<zeebe:header key="resultExpression" value="=body" />
<zeebe:header key="retryBackoff" value="PT0S" />
</zeebe:taskHeaders>
</bpmn:extensionElements>
<bpmn:incoming>Flow_0yqe20b</bpmn:incoming>
<bpmn:outgoing>Flow_1r4dbfu</bpmn:outgoing>
<bpmn:messageEventDefinition id="MessageEventDefinition_0wbei0k" messageRef="Message_3m04392" />
</bpmn:intermediateCatchEvent>
<bpmn:sequenceFlow id="Flow_0yqe20b" sourceRef="Activity_099dv3b" targetRef="customerInformationReceived" />
<bpmn:serviceTask id="Activity_099dv3b" name="Request missing information from the customer">
<bpmn:extensionElements>
<zeebe:taskDefinition type="job" />
</bpmn:extensionElements>
<bpmn:incoming>Flow_1tykdw0</bpmn:incoming>
<bpmn:outgoing>Flow_0vnblrd</bpmn:outgoing>
<bpmn:outgoing>Flow_0yqe20b</bpmn:outgoing>
</bpmn:serviceTask>
</bpmn:process>
<bpmn:message id="Message_02eoed2" name="customer_accepts_offer">
Expand Down Expand Up @@ -403,6 +398,15 @@
<dc:Bounds x="1210" y="300" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_12xvzj7_di" bpmnElement="customerInformationReceived">
<dc:Bounds x="652" y="452" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="643" y="495" width="55" height="40" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_12tqpbh_di" bpmnElement="Activity_099dv3b">
<dc:Bounds x="510" y="430" width="100" height="80" />
</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 @@ -459,12 +463,6 @@
<bpmndi:BPMNShape id="Gateway_1i87sao_di" bpmnElement="Gateway_1i87sao" isMarkerVisible="true">
<dc:Bounds x="645" y="315" width="50" height="50" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_12xvzj7_di" bpmnElement="customerInformationReceived">
<dc:Bounds x="652" y="432" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="643" y="475" width="55" height="40" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Gateway_0h8t0o8_di" bpmnElement="Gateway_0h8t0o8" isMarkerVisible="true">
<dc:Bounds x="725" y="315" width="50" height="50" />
<bpmndi:BPMNLabel>
Expand All @@ -477,9 +475,6 @@
<dc:Bounds x="311" y="298" width="78" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0j6fkc3_di" bpmnElement="missingInformationRequest">
<dc:Bounds x="510" y="430" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_0oxv702_di" bpmnElement="Event_0oxv702">
<dc:Bounds x="1412" y="362" width="36" height="36" />
<bpmndi:BPMNLabel>
Expand Down Expand Up @@ -562,11 +557,11 @@
<di:waypoint x="490" y="470" />
<di:waypoint x="510" y="470" />
<bpmndi:BPMNLabel>
<dc:Bounds x="481" y="414" width="18" height="14" />
<dc:Bounds x="481" y="413" width="18" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1r4dbfu_di" bpmnElement="Flow_1r4dbfu">
<di:waypoint x="670" y="432" />
<di:waypoint x="670" y="452" />
<di:waypoint x="670" y="365" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1t0w6hs_di" bpmnElement="Flow_1t0w6hs">
Expand All @@ -577,12 +572,6 @@
<di:waypoint x="695" y="340" />
<di:waypoint x="725" y="340" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0vnblrd_di" bpmnElement="Flow_0vnblrd">
<di:waypoint x="610" y="470" />
<di:waypoint x="631" y="470" />
<di:waypoint x="631" 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" />
Expand All @@ -591,6 +580,10 @@
<di:waypoint x="268" y="340" />
<di:waypoint x="332" y="340" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0yqe20b_di" bpmnElement="Flow_0yqe20b">
<di:waypoint x="610" y="470" />
<di:waypoint x="652" y="470" />
</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 Down
Loading

0 comments on commit bad3426

Please sign in to comment.