Message flow - Start process by message

Hi,

Part of my process is the following:

The Send task “Send “layer full” message” is executed but the message flow doesn’t initiate a new message to the lower pool.
What do I miss?
I also created a java class “InstantiateProcessByMessageDelegate”

import org.camunda.bpm.engine.RuntimeService;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;


public class InstantiateProcessByMessageDelegate implements JavaDelegate {

  public void execute(DelegateExecution execution) throws Exception {
    RuntimeService runtimeService = execution.getProcessEngineServices().getRuntimeService();
    runtimeService.startProcessInstanceByMessage("layer_reached");
  }
}

Thanks!

Hi @kontrag,

are you sure that your second pool is marked as executable?

Cheers, Ben

Hi @benhoffmann,

Yes it is.

Edit: Fixed!
I should type my Java class “InstantiateProcessByMessageDelegate” in the Send task "Send “layer full” (in Implementation field).

I now face issues of passing a variable from one pool to the other.

You can add a Map payload with the message.

Hi @Niall,

For my understanding, could you please explain me the logic of mapping?
In my model above, should I create an Input/Output parameter in the Receive “Send ‘layer full’ message” task and then the same parameters in “place layer” task in the other pool?
In the message events, I don’t understand where to specify the payload you mention.

Thanks!

In your Java Delegate you could do something like this:

		Map<String, Object> processVars = execution.getVariables();
		
		execution.getProcessEngineServices()
		.getRuntimeService()
		.startProcessInstanceByMessage("SomeMessage", processVars);
		
2 Likes

One more thing:

You should consider placing an end event after your send task. Although that is not mandatory, that it can be considered as best practice.

Cheers, Ben

Thanks @benhoffmann

The point is that I don’t want to terminate the process instance there as it’s a part of a call activity. Also from the second pool I want to return back to to upper pool.
I know that it may look odd but I think it solves my business case.

Best,
Kostas

Allright.

Just keep in mind that a process instance will not be terminated by an ordinary none end event. This only removes a token from the instance, the instance itself will be running until all tokens have been removed.

		Map<String, Object> processVars = caseExecution.getVariables();
		RuntimeService runtimeService = caseExecution.getProcessEngineServices().getRuntimeService();			
      	runtimeService.createMessageCorrelation("MessageName");	      	
      	Execution exID = runtimeService.createExecutionQuery().messageEventSubscriptionName("MessageName").singleResult();	
        runtimeService.messageEventReceived("MessageName", exID.getId(), processVars);