I created an example, which hopefully helps to explain that.
First you create a workflow via the Zeebe modeler or the Java model API.
You can use input and output mappings to create new variables or define how variables should be merged into the workflow instance variables, please see the documentation for further information.
I created a similar workflow based on your Question, with an output mapping on the first task.
// given
final var client = CLIENT_RULE.getClient();
// deploy workflow
final var workflow =
Bpmn.createExecutableProcess("processId")
.startEvent()
.serviceTask(
"task1",
t ->
t.zeebeTaskType("typeOne")
.zeebeOutput("glossary.GlossDiv.GlossList.GlossEntry.GlossDef", "GlossDef"))
.serviceTask("task2", t -> t.zeebeTaskType("typeTwo"))
.endEvent()
.done();
client.newDeployCommand().addWorkflowModel(workflow, "process.bpmn").send().join();
// create workflow instance with payload
client
.newCreateInstanceCommand()
.bpmnProcessId("processId")
.latestVersion()
.variables(
"{"
+ "\"glossary\": {\"title\": \"example glossary\","
+ "\"GlossDiv\": {"
+ "\"title\": \"S\","
+ "\"GlossList\": {"
+ "\"GlossEntry\": {"
+ "\"ID\": \"SGML\","
+ "\"SortAs\": \"SGML\","
+ "\"GlossTerm\": \"Standard Generalized Markup Language\","
+ "\"Acronym\": \"SGML\","
+ "\"Abbrev\": \"ISO 8879:1986\","
+ "\"GlossDef\": {"
+ "\"para\": \"A meta-markup language, used to create markup languages such as DocBook.\","
+ "\"GlossSeeAlso\": [\"GML\", \"XML\"]"
+ "},"
+ "\"GlossSee\": \"markup\""
+ "}"
+ "}"
+ "}"
+ "}"
+ "}").send().join();
To access the payload you simple call a corresponding method on the given Job.
For example getVariables
returns an string in JSON format, but you can also use the getVariablesAsMap
method to access the variables easier.
client
.newWorker()
.jobType("typeOne")
.handler(
(jobClient, job) -> {
System.out.println(job.getVariables());
jobClient.newCompleteCommand(job.getKey()).send().join();
})
.name("workerOne")
.open();
Our handler code will for example print out
{"glossary":{"title":"example glossary","GlossDiv":{"title":"S","GlossList":{"GlossEntry":{"ID":"SGML","SortAs":"SGML","GlossTerm":"Standard Generalized Markup Language","Acronym":"SGML","Abbrev":"ISO 8879:1986","GlossDef":{"para":"A meta-markup language, used to create markup languages such as DocBook.","GlossSeeAlso":["GML","XML"]},"GlossSee":"markup"}}}}}
For the second task we could write the following code.
final CountDownLatch secondJobLatch = new CountDownLatch(1);
client
.newWorker()
.jobType("typeTwo")
.handler(
(jobClient, job) -> {
System.out.println(job.getVariables());
jobClient.newCompleteCommand(job.getKey()).send().join();
secondJobLatch.countDown();
})
.name("workerTwo")
.open();
secondJobLatch.await();
This will print out:
{"GlossDef":{"para":"A meta-markup language, used to create markup languages such as DocBook.","GlossSeeAlso":["GML","XML"]},"glossary":{"title":"example glossary","GlossDiv":{"title":"S","GlossList":{"GlossEntry":{"ID":"SGML","SortAs":"SGML","GlossTerm":"Standard Generalized Markup Language","Acronym":"SGML","Abbrev":"ISO 8879:1986","GlossDef":{"para":"A meta-markup language, used to create markup languages such as DocBook.","GlossSeeAlso":["GML","XML"]},"GlossSee":"markup"}}}}}
So if you want to minimize the variables which the job has access to you can use input variables. If you want to have an result in your workflow variables differently stored you can use the output mapping. With the output mapping you can also overwrite your variables completely.
I hope this helps.