How to create instance with start message event in JAVA

Hi everyone,

I am struggling find any examples or reference docs on how to make an instance in Java when you have a start message event?
Currently, what I am trying to do is to make an instance with no variables (because I need to reference my .bpmn file in there I believe and I cannot do it in the start message event). And then I am publishing the message:

private ZeebeClient client;

final WorkflowInstanceEvent wfInstance = client.newCreateInstanceCommand()

                                .bpmnProcessId(processId)

                                .latestVersion()

                                .send()

                                .join();

                        

                        logger.info(String.format("Successfully created zeebe workflow instance and data variable name: %s", dataVariableName));

                }

                client.newPublishMessageCommand()

                         .messageName("hello")

                         .correlationKey("")

                         .variables(data).send().join();

I get this error message:

Command 'CREATE' rejected with code 'INVALID_STATE': Expected to create instance of workflow with none start event, but there is no such event; Processor Administratively Yielded for 1 sec: io.zeebe.client.api.command.ClientStatusException: Command 'CREATE' rejected with code 'INVALID_STATE': Expected to create instance of workflow with none start event, but there is no such event

Any ideas what is going on and where to find relevant docs for this?

I got it fixed. I just commented out the instance creation (newCreateInstanceCommand).

2 Likes

Same boat here. I am trying to figure out how to correlate the message to the message start event. But the message start event doesn’t have a correlation key field in BPMN?

Also, did you just remove this entirely?
final WorkflowInstanceEvent wfInstance = client.newCreateInstanceCommand()
.bpmnProcessId(processId)
.latestVersion()
.send()
.join();

It seems that Message Start Event works with Correlation Key if it is in the event sub-process. How would I start a parent process using the message start event? Do I just publish a message from the client with only the matching message name, but without a Correlation Key?

1 Like

@yangzi-jiang

message-start-events

If the correlationKey of a message is empty then it will always create a new process instance and does not check if an instance is already active.

1 Like

Okay, thank you! So basically, since the message start event, if in a root instance, cannot accept correlationKey in BPMN, therefore I cannot ensure only one instance is created

1 Like

@yangzi-jiang
Sorry for the late reply. Yes that is correct as @lzgabel also has pointed out.
For that particular problem, I did remove the instance creation entirely as you pointed out.

Hey @yangzi-jiang

you can if you always use the same correlation key (e. g. static value), then only one instance is created. If the process instances is completed the next one will be created.

You can find here fitting engine tests, which describes the scenario.

Hope that helps.

Greets
Chris

2 Likes