Receive Task Not working

Hi,

I have been trying to receive a msg, in my main process_workflow, since two days. But repeatedly encountering MismatchingMessageCorrelationException. Please can some throw light on how to use receive task clearly,

Few points:

  • most of the tutorials highlight the usage of message-start-event(not receive task)
  • tried to search for resolution on various topics created here on camunda forum, most of them ended being dead, without proper responses.
  • I tried with a message-start-event, it is working fine in such case, but doesnt fit my scenario, as usage of msg-start-event, would mean disconnected process.
  • lets make the community rich by giving working solutions please :slight_smile:

process_workflow.bpmn (10.5 KB)

Process is halt at receive msg task

Updated, bpmn diagram and screeshot
Let me know if you need to know more details,
If possible can you clearly explain, the usage of Receive task implementation, with javaDelegates
@StephanHaarmann

Hi @Srinish,

In your image, you’re a pointing to an “intermediate message catch event” and not to a task. However, this detail does not matter because they are implemented in the same way.
When you want to catch a message in a running process instance, you must correlate the message and the instance. The relationship is 1-to-1. This means every message is received by exactly one process instance. Correlation must be unambiguous.
The correlation is based on two elements:

  • the message code — this is used to match the message to a process model and is defined once per message receive node.

  • the correlation key — the correlation key is used to link a message to one specific process instance. This is usually a variable or the business key.

When correlating a message to an intermediate event, you must provide this data. The following example correlates the message to a message catch event configured with a message called “messageName” and a process instance with business key “AB-123” and variable “myVariable”
is equal to “myValue”:

runtimeService.createMessageCorrelation("messageName")
  .processInstanceBusinessKey("AB-123")
  .processInstanceVariableEquals("myVariable", "myValue")
  .correlateWithResult();

Note, it is not necessary to provide both the business key and
You can achieve the same via the REST API.
More information on message correlation are provided in the documentation.

1 Like

Updated
bpmn file:
process_workflow.bpmn (10.5 KB)

Hi @StephanHaarmann ,

Thanks for sharing your response on usage of correlation of a message.
Here in the following steps, I will try to explain, the order of flow being followed which is resulting into the above error situation.

  1. start the workflow, from the start event(id: StartEvent_1), which results in generation of a following journey response. here batchUuid acts as business key

  2. the following scenario occurs, where workflow is waiting for a message, as shown here

  3. Further, I try to place a message using a application-rest-api using runtimeService


    @Autowired
    private ProcessEngine camunda;

    @PostMapping(value = "camunda/correlate-message/{msg}/{businessKey}")
    public void testCamundaCorrelateMessage(@PathVariable("msg") final String msg,
            @PathVariable("businessKey") final String businessKey) throws Exception {
        camunda.getRuntimeService().createMessageCorrelation(msg)
                .processInstanceBusinessKey(businessKey)
                .setVariable("order_id", "1234ABCD")
                .correlate();
    }

  1. at this moment is when I encounter the following error
ERROR 2022-09-20 20:41:04.071 [-7083-exec-3] org.camunda.bpm.engine.context.logError:160                            : ENGINE-16004 Exception while closing command context: Cannot correlate message 'MSG1': No process definition or execution matches the parameters
org.camunda.bpm.engine.MismatchingMessageCorrelationException: Cannot correlate message 'MSG1': No process definition or execution matches the parameters
	at org.camunda.bpm.engine.impl.cmd.CorrelateMessageCmd.execute(CorrelateMessageCmd.java:88)
	at org.camunda.bpm.engine.impl.cmd.CorrelateMessageCmd.execute(CorrelateMessageCmd.java:42)
	at org.camunda.bpm.engine.impl.interceptor.CommandExecutorImpl.execute(CommandExecutorImpl.java:28)

Sorry for such a long post.

As needed, I relaying a message for a process instance by passing the corresponding message key and businesskey, which is resulting into an erroneous situation for me.
I have newbie in camunda-workflow.
would be able to help, in identifying the missing understanding here, as I trying to consume a message.

Actual background: The requirement is that, an external microservice will be making callback to our application, written with the help of camunda. But for a single-process-instance, it can consume multiple callbacks, since we are creating multiple journeys. To handle such a scenario. An application rest-api will be exposed for callback, which inturn will post a message using runtimeService(), Initially, started working out by consuming single message, and performing certain processing, but eventually I would have to a scenario, where for a single businessKey, multiple messages need to be consumed and processed. Hope you understood the flow.

As a learning camunda-java-developer, would you suggest any patterns to be followed in above kind of scenarios.

Any suggestion will be valuable to our team.

Thanks
Srinish

To try a theory, could you perhaps try changing your code slightly?

    @Autowired
    private ProcessEngine camunda;

    @PostMapping(value = "camunda/correlate-message/{msg}/{businessKey}")
    public void testCamundaCorrelateMessage(@PathVariable("msg") final String msg,
            @PathVariable("businessKey") final String businessKey) throws Exception {
        camunda.getRuntimeService().createMessageCorrelation(msg)
                .processInstanceBusinessKey(businessKey)
                .correlate();
    }

Your error message is saying that the underlying query returned 0 records.
Since you’re trying to both set a variable and include that same variable in your query, I’m going to guess that your variable isn’t already set when it’s trying to correlate.

You could also try doing the correlation from Postman rather than your code, to get yourself fully understanding how the communication is going… It almost looks like you’re going from Camunda in Java with Java delegates out to a REST interface back into Camunda… which just seems convoluted.

2 Likes