More complex event registry payload description

Hi! I’m experimenting with event registry introduced in 6.5.0.
Everything so far for the moment - I can connect flowable with Kafka and initiate process then new event posted into Kafka.

But I have question - all samples I found has quite simple event payload - suitable for “flat” event data.

Lets imagine I have more complex event - there some variables - are JSON object itself. For example:

{“var1”:{“var2”:“value2”, “var3”:“value3”}}

How can I define event payload, so, whole var1 placed into process context? or, for example, only var2 placed into process context as String?

Hi

I’m trying to manage complex payloads as well.
Did you make any progress with this ?

Thanks
Inbal

Hi Inbal!
Unfortunately no - did not resolved it yet

Indeed - currently complex mappings can be done by plugging in custom pipeline components, e.g. https://github.com/flowable/flowable-engine/blob/master/modules/flowable-event-registry/src/test/java/org/flowable/eventregistry/test/CustomEventProcessingPipelineTest.java#L69

In the future, we want to improve the support there to do this without code changes.

Hi Joram! Thank you very much for advice! I will try to implement with using these custom components.

Thanks Joram for this answer
I just upgraded to version 6.6.0 - and i see there is a new json data type supported for variables.
I was able to extract the parts of my complex payload as separate json variables - but now i’m trying to figure out how i can use them (for example - how can i use such a variable in an expression in a gateway).
Are there any examples for this use i can look at as reference ?

Thanks a lot for all the support in this forum
Inbal

Hi Inbal!
I was not able to find information about json variables. Can you share sample of “payload” in event definition to accept complex json data?

OK, actually I found how to map json in event registration (just to use json variable type). Everything is ok - JSON value passed from Kafka to Flowable Process.
Now same question as Inbal asked - how can I operate with this variable in task form (for example)? Any samples?

Hi

I managed to work with those json variables.
In the event definition - i set the variable with type = json.
Then in my flow built using Modeler - i could not set the variable as json - so i ended up saving the xml of the flow and editing it to define the variable as json as well.
And now i could use it easily.
e.g. my incoming json was
{“eventKey”:“newImportFileEvt”, “file”:{“key”:“abcd”, “type”:“csv”}}
So my variable called “file” with type = json holds {“key”:“abcd”, “type”:“csv”} and i managed to use this in expressions like file.key & file.type

Hope i’m doing it the right way … works for me
Inbal

Hi Inbal!
Can you share part of process definition?
My problem: I defined variable in eventRegistry definition (payload part) as json.
In Process Definition I also defined it as JSON
<flowable:eventOutParameter xmlns:flowable="http://flowable.org/bpmn" source="event" sourceType="json" target="event"></flowable:eventOutParameter>

Then I’ve added Script Task with simple script:

org.slf4j.LoggerFactory.getLogger("theScriptTask").info("event Value: {}", event);
org.slf4j.LoggerFactory.getLogger("theScriptTask").info("event type: {}", typeof event);

I can see value of my variable and type object:

2020-11-08 13:16:44.596 INFO 8244 — [ task-1] theScriptTask : event Value: {“from”:“F”,“to”:“D”,“amount”:570.0,“ALERT_REASON”:“Transaction to high”}
2020-11-08 13:16:44.601 INFO 8244 — [ task-1] theScriptTask : event type: object

Everything is OK so far. BUT:

  • I cannot access any attributes - event.from, event.to returns undefined
  • If I’m trying to call (in ScriptTask) Object.keys(event) I’ve received exception “event is not Object”

So, still question how to access attributes of specific json variable, received from event. ANy advice will be really helpful!

OK, partially answered to my question.
Varialbe with type “json” passed into ScriptTask not as JavaScript Object, but as " * com.fasterxml.jackson.databind.node.ObjectNode" object.
So,

event.get(“ALERT_REASON”)

getting me required variable.

This is how i defined my variable from the event

<flowable:eventOutParameter source=“file” sourceType=“json” target=“file” targetType=“json”></flowable:eventOutParameter>

And this is how i used it for generating the payload for the next event

<flowable:eventInParameter sourceExpression="${file.key}" target=“fileKey” targetType=“string”></flowable:eventInParameter>

Hope this helps