Messages/Events catching on process models

Hi,

I would like to ask the community for guidance to understand and try the following:

Assuming I have a process model representing a manufacturing process. While the process is running, there could be events/messages from the environment (e.g. a fire in the factory - these events are raised, no need to worry about this) that needs to be captured by the process engine and act accordingly (e.g. stop or pause the process).

One thought was to put the whole process in a subprocess and put boundary BPMN errors to catch such messages, but I don’t like that idea.
Or use event subprocesses like this suggestion Interrupting event subprocess and resume parent process but then I have to put conditional events everywhere in the main process model and not sure if it still does what I want.

I assume configuring an ActiveMQ integration is better. But I’m not familiar with the concepts there and I would appreciate if anyone can point me simple tutorials. I guess I need something like subscribing in a queue/topic in the beginning of a process and once messages are in the queue, my model should be able to catch them. But any simple examples to look on?

Thanks,
Kostas

Hi Kostas,

you can model this behavior using a boundary event or an (interrupting) event subprocess. The conditional events are not necessary, depending on your use case.

Why don’t you like these approaches?

Best regards,
Philipp

Hi @Philipp_Ossler,

Using boundary events is not really an option because my process calls other call activities and things become more complicated with nesting of processes.

Event subrpocess is an option that I want to try out. But not sure what type of start event should I put. I receive external messages from an open websocket connection and from those I should trigger the event subprocess. I guess it has to be a message start event, right? Or can an error event be triggered “externally” (I mean without having a throw error event somewhere in the main process)? My first thought is that depending on the incoming websocket message, I can set the “error_code” to a value and if this matches with the error code of the error start event, the event subprocess will be triggered. But how is the “error_code” read by the engine at the error throwing event? Is it a process variable?

Hi again,

I have a process like the following:

At any point during the process, an “external message” (through a websocket connection) can arrive.
In that message I have the process_instance_id and I can get the runtime.
I want to trigger the Error Event in the event subprocess. But how?
I see the example here Throw bpmn errors from delegation code, but how can I access the Delegateexecution?

Hi Kostas,

you can’t throw a BPMN error event from outside of the process. You must use a message event which can hold the error code as payload (i.e. variable).

Does this help you?

Best regards,
Philipp

Hi @Philipp_Ossler,

I’m trying to use the message start event in the event subprocess as you suggested but I have some difficulties how to correlate the incoming message. I get error

Cannot correlate message ‘New_event_arrived’: No process definition matches the parameters

I read the documentation Message Events | docs.camunda.org
but it doesn’t say anything about event subprocesses.
Actually it says “It contains the type of the correlation, which is either execution or processDefinition.”.
But how is the event subprocess with a start message event is treated?
As an execution type or processDefinition type?

I tried the following code:

runtimeService.createMessageCorrelation("New_event_arrived")
   .processInstanceBusinessKey(runtimeService.getVariable(processInstanceId,"uniqueBusinessKey").toString())
   .setVariable("eventId", eventId)
   .correlateAllWithResult();

The uniqueBusinessKey is the one I have in the main process.

Thanks!

Hi Kostas,

if the message name and the business key is correct then your code should work. Can you share a failing test case to reproduce the issue?

Best regards,
Philipp

Hi @Philipp_Ossler

Here’s my test process:

and the model here:
https://cawemo.com/diagrams/58053f2f-0501-47ab-bcca-30c7e5bb6b5a--event-sub-msg?v=638,307,1

The uniquebusinesskey I pass in the message correlation is the one I create in the beginning of the main process. Is it a correct approach?

I found this example code/SendCancelMessage.java at master · camunda-consulting/code · GitHub
in which the correlation is much simpler.

Hi @kontrag,

I’m a bit unfused. I don’t know the method execution.setUniqueBusinessKey(...)? Do you set a variable?

Please note that you can start a process instance with a given business key. This is a property of the process instance and no variable.
If you start the process instance with a business key then you can use the key in the correlation builder as processInstanceBusinessKey. Otherwise, you have to set it as correlationKey(...).

Best regards,
Philipp

Yes, my bad. I simply set a variable in “setUniqueBusinessKey”. I thought I could use this in the correlation.
Thanks!