forked from aleksander-dytko/Webinar-8.6
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b98c44a
commit bad3426
Showing
5 changed files
with
487 additions
and
115 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
} | ||
} | ||
} | ||
} | ||
|
@@ -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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.