Message Start event within event subprocess

Hi ,

My use case says I need to cancel a running process If I received another duplicate request.
For I had created an event subprocess within which I added message start event and called service task to update status to cancel in db and terminate the process.
I had created a Process Variable named businessKey in my Process.
In the event sub process , message start event I am trying to correlate using this businessKey. I added Message Name as cancelEvent , correlationKey as businessKey (variable name) and I am using the below method to correlate. However the correlation never happened. Please advise.
zeebeClient
.newPublishMessageCommand()
.messageName(messageName)
.correlationKey(correlationKey)
.variables(properties)
.send().exceptionally(throwable → {
throw new ZeebeException(“Could not correlate instance for correlationKey {” + correlationKey + “}”, throwable);
}).toCompletableFuture().join();

If you have an interrupting event subprocess, you don’t need to explicitely cancel the process as it’ll be completed once your event subprocess is done (at least if it’s in the scope of the whole process).
As for your message correlation its hard to say. Did you try correlating to another message event?
Are you sure your correlation key and message name are correct?
The message name and correlation key need to be the same in the running process instance and your call.

Yes ours is interupting event subprocess. It should end the flow once it correlates using message name and correlationKey.

In our case I am using message name as a constant “CancelEvent” and correlationKey is processInstanceKey (feel expression variable name) . In my main process I have a processVariable with name as processInstanceKey wherein I set processInstanceId.

I trigger message correlation endpoint from application it doesn’t correlates.
Am I doing anything wrong here ? Or Should I have message name as dynamic / feel expression ?

Created an example that works. My message definition in the process model looks like this:

  <bpmn:message id="Message_0f0ia98" name="SubprocessMessage">
    <bpmn:extensionElements>
      <zeebe:subscription correlationKey="=orderId" />
    </bpmn:extensionElements>
  </bpmn:message>

It’s used in an event subprocess like this, if you look at the XML:

    <bpmn:subProcess id="Activity_1gnnk4v" triggeredByEvent="true">
      <bpmn:startEvent id="Event_1cj54oq">
        <bpmn:outgoing>Flow_0uy551h</bpmn:outgoing>
        <bpmn:messageEventDefinition id="MessageEventDefinition_0i3yee0" messageRef="Message_0f0ia98" />
      </bpmn:startEvent>

You can then correlate your message to this event subprocess by calling the Zeebe client as follows (if the variable orderId has the value “123456”):

        zeebe.newPublishMessageCommand()
            .messageName("SubprocessMessage")
            .correlationKey("123456")
            .send().join()

Hi @rohwerj , Thanks for your response.I tried above example and it worked.
However I have one observation.
Mine is a asynchronous Parent process. So any process Variables which I set before creating a process instance , only those process variables are available for correlation. Process Variables like Process instance Key , or BusinessKey that we update during the process runtime are not visible during message correlation through event sub process.

This is correct the message subscription is resolved when the activity is activated, which for a event subprocess start event is during instantiation of the process instance.
You could have your event subprocess in a different scope and then it would be calculated once you enter the scope (at least I think that’s how it should be).

Similar scenario worked fine in Camunda7. Only difference was Parent Process was synchronously started and was asynch after a particular service task.Event Sub process was in scope of Parent process.

But it is at least true for Camunda 8. See here

The following block describes what I’m saying:

A subscription is closed when the corresponding element (e.g. the message catch event), or its scope is left. After a subscription is opened, it is not updated (for example, when the referenced process instance variable is changed.)

ok. understood. Thanks for Clarifying !!!