"createMessageCorrelation" raised error "No process definition or execution matches the parameters"

I’m creating a PoC to illustrate a delegate could create a message which is to be caught by a boundary message event.

However, the “createMessageCorrelation” raised error “No process definition or execution matches the parameters”

The flow is named as “messageFlow”

This is how the workflow is started.

processEngine
        .getRuntimeService()
        .startProcessInstanceByKey("messageFlow", params);

This is how the boundary event looks like,

Here is the delegate code where a message is supposed to raise.

MessageCorrelationResult result =
                    execution
                            .getProcessEngine()
                            .getRuntimeService()
                            .createMessageCorrelation("NoHello")
                            .processInstanceBusinessKey("messageFlow")
                            .setVariable("payment_type", "creditCard")
                            .correlateWithResult();

And i’m getting error as

2019-12-04 10:37:48.237 ERROR 96719 --- [nio-8080-exec-2] org.camunda.bpm.engine.context           : ENGINE-16004 Exception while closing command context: Cannot correlate message 'NoHello': No process definition or execution matches the parameters

org.camunda.bpm.engine.MismatchingMessageCorrelationException: Cannot correlate message 'NoHello': No process definition or execution matches the parameters
	at org.camunda.bpm.engine.impl.cmd.CorrelateMessageCmd.execute(CorrelateMessageCmd.java:88) ~[camunda-engine-7.12.0.jar:7.12.0]
	at org.camunda.bpm.engine.impl.cmd.CorrelateMessageCmd.execute(CorrelateMessageCmd.java:42) ~[camunda-engine-7.12.0.jar:7.12.0]
...

Hi @oakgreen,

I assume that your process instance has no business key messageFlow.

Here you can find further details about the business key and how to set it: https://blog.camunda.com/post/2018/10/business-key/.

As an alternative you can use correlation keys, which are a set of process variables, identifying a single process instance.

Hope this helps, Ingo

I updated the code to start the process and pass in the business key.

processEngine
        .getRuntimeService()
        .startProcessInstanceByKey("messageFlow", "123", params);

Here messageFlow is the instanceKey while 123 is the businessKey

In the delegate where the message to be created,

log.info("--> Raise Message? {}", startProcessRequest.isRaiseMessage());
log.info("--> BusinessKey={}", execution.getProcessBusinessKey());
if (startProcessRequest.isRaiseMessage()) {
    // create a message correlation
    MessageCorrelationResult result =
            execution
                    .getProcessEngine()
                    .getRuntimeService()
                    .createMessageCorrelation("NoHello")
                    .processInstanceBusinessKey("123")
                    .setVariable("payment_type", "creditCard")
                    .correlateWithResult();
}

Passed 123 to .processInstanceBusinessKey()

I can verify from log the businessKey is 123. But the same error still stands.

Where are you running that code from?
A process cannot trigger a message event in it’s own instance. (just wanted to check that the process is not sending a message to itself.)

A process cannot trigger a message event in it’s own instance

I am trying to raise a message from a subprocess and caught by a boundary event. Is this valid?

Nope, afraid not - you’re using an embedded sub process so it’s actually the same instance.
The message event is specifically for contacting other processes - if you’d like to have an event trigger and interrupt your sub process it’s much easier to just a conditional event.

The conditional event can simply wait for a variable to become true and in your code you can set that variable to the instance which will trigger the event an interrupt the subprocess. This would have the same affect as if you sent a message - except it’s a lot easier.

Hi Niall,

I’m attaching the diagram.

What if I put 2 sub-processes. Is this valid for subprocess-A to raise message, while subprocess-B to capture it?

Yup, sorry you can’t do that… that standard doesn’t allow it.
You’re better of using a conditional event.
Although - you can also cheat you can do something like this

    execution.getProcessEngineServices().getRuntimeService()
                .createMessageCorrelation("messageName")
                .processInstanceBusinessKey("someKey")
                .correlateAllWithResult();

That’ll work.

Thanks a lot @Niall