REST, Event-Subprocess and local Variables

Hi there,
currently i’m evaluating different solutions to process “out-of-order messages”. One of my setups is having a process with 1…n signals an an embedded event subprocess to receive message and puth them in the right order for signal_1 … signal_n.
Those message allways have variables embedded which i would like to be local to the execution context of the spawned subprocess.
Rest-Calls look like this(VS-Code REST-Extension):

### Send dispatching-Event
# @name sendMessage
POST /engine-rest/message HTTP/1.1
Host: localhost:8080
Content-Type: application/json
{
  "messageName" : "dispatchEvent",
  "businessKey" : "1234",
  "processVariablesLocal" : {
    "eventSource" : {"value" : "yyy", "type": "String"},
    "eventName" : {"value" : "xxx", "type": "String"}
  },
  "resultEnabled" : true,
  "variablesInResultEnabled" : true
}

But instead of being local to the execution, eventSource/eventName are global!
With respect to Set local variables in event subprocess via REST-API - #11 by thorben and https://jira.camunda.com/browse/CAM-10380 this behaviour is correct, but unfortunately docs are still not updated. IMHO, that’s not how it should work.

Using a StartListener on the message start event, i can transfer variables from global to local context, but overall this is prone to race conditions when messages are received at short intervalls.
(Yes, it’s possible to use transient variables, but it’s quite hard to understand if you’re not into it).

Next i tried to start subprocess without variables, receiving the spawned executionid and pass variables:

### Send Vars to execution context
@name setEcVar_EventName
Put /engine-rest/execution/{{sendMessage.response.body.$.[0].execution.id}}/localVariables/eventName HTTP/1.1
Host: localhost:8080
Content-Type: application/json
{"value" : "name of the event", "type": "String"}

Same result/next problem here. Well it could have worked, if the returned executionID of subprocess start wouldn’t be the one of processinstance context.
So you have to query all activities and executions to find the right context (which could be quite hard, if you don’t have any information how to distinct subprocess-instances). So either i didn’t get the trick, docs are VERY misleading or the api-behaviour should be reconsidered.

In general, it’s not clear whats the default context for variables, e.g. using a br-task within subprocess result in global results, which again, is prone to errors. Initializing the result variable as local before the br-task it works as expected.

So is there any best practise for working with local data?

Regarding my actual problem “out-of-order” messages, im really looking forward to the message buffer plugin.

KR, Joachim