1

Currently working with Scala and zeebe, and in my bpmn I have some service task, which get or send data type of json and my main goal parse this data jsonpath, for example:

{
    "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"
                }
            }
        }
    }
}

ServiceTask make get request from some REST API, and I can get

"GlossDef": {
      "para": "A meta-markup language, used to create markup languages such as DocBook.",
      "GlossSeeAlso": ["GML", "XML"]
}

by giving jsonpath = "$.glossary.GlossDiv.GlossList.GlossEntry.GlossDef", but I want to write this json path on my zeebe bpnm and I don't know how to access zeebe jobWorker input/output variables

enter image description here

and the main question is how I can access and use ioMapping which looks like below:

<zeebe:ioMapping>
  <zeebe:output source="glossary.GlossDiv.GlossList.GlossEntry.GlossDef" target="GlossDef" />
</zeebe:ioMapping>
Baktiyar Bekbergen
  • 374
  • 2
  • 4
  • 24
  • Sorry but I'm not 100% what the question is. So you have workflow instance payload (the big one) and would like to extract payload to use it in the service task. For that you use the described jsonPath but this didn't worked? What are the problems you encountered? – Zelldon Jan 08 '20 at 13:00
  • @Zelldon let's say I have two service task on my zeebe bpnm, and on each task I declare some input/output which I want to use like jsonpath, when I get data from service and I parse it by by input/output and send it to second service – Baktiyar Bekbergen Jan 09 '20 at 04:46

1 Answers1

2

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.

Zelldon
  • 5,396
  • 3
  • 34
  • 46