cancel
Showing results for 
Search instead for 
Did you mean: 

start activiti with message start event

arag
Confirmed Champ
Confirmed Champ

Hi,

I have a simple model bpmn (start message and two tasks Smiley Happy ), the problem is that i dont know how to start the flow with a message,

i worked with JMS and now i can get the message and all the data that i need but how i can start the flow with my message ??? what is the secret ?? O.O jajaja

Please i need help

ProcessInstance startProcessInstanceByMessage(String messageName); ProcessInstance startProcessInstanceByMessage(String messageName, Map<String, Object> processVariables); ProcessInstance startProcessInstanceByMessage(String messageName, String businessKey, Map<String, Object> processVariables);

The "String messageName" is my message or the name of my process? or the message property "name" in bpmn diagram? 

How i can pass to activiti all the email data?

Thats my problem... sorry if this sounds silly 

(Ji My english is bad cause i speak spanish and im practicing o.o )

Thanks for your time 

1 ACCEPTED ANSWER

gdharley
Elite Collaborator
Elite Collaborator

Within the BPMN Process definition you will need to create a message definition in the process model:

This is the message you will use to start the process instance.

Next, you need to add a "Start Message Event" in your process and subscribe to the message you created:

Now, in order to start the instance, you can either use the REST API:

POST /activiti-app/api/runtime-instance

{    "message":"myMessage",    "variables": [       {         "name":"myVar",         "value":"This is a variable",       }    ] }

Alternatively, if you are using the Java API use:

ProcessInstance startProcessInstanceByMessage("myMessage");

If you are looking for a complete example using java code, take a look at 

MessageStartEventTest.java in the Activiti source Activiti/MessageStartEventTest.java at activiti-5.22.0 · Activiti/Activiti · GitHub 

Look for "testingSingleMessageStartEvent" test.

Hope this helps,

G

View answer in original post

4 REPLIES 4

jearles
Star Contributor
Star Contributor

Ara,

Since you've already done the leg-work for creating the JMS integration, the rest is just utilizing Activiti's built-in APIs to call the appropriate methods to kick off a process. The API Docs list several methods similar to the one you highlighted:

startProcessInstanceByMessage(<params>)

Me personally, I like to look at Activiti's Tests in Github to see how these things work; but basically what you're going to end up doing is: Create a named message event in the process diagram, then call it as the 'messageName' parameter you were asking about. The User Guide documentation is a pretty solid reference as to how these work and setting them up.

Hope this helps to bridge your knowledge here Smiley Happy
-JEarles

arag
Confirmed Champ
Confirmed Champ

Great i will try to download the example... Thanks!!!

gdharley
Elite Collaborator
Elite Collaborator

Within the BPMN Process definition you will need to create a message definition in the process model:

This is the message you will use to start the process instance.

Next, you need to add a "Start Message Event" in your process and subscribe to the message you created:

Now, in order to start the instance, you can either use the REST API:

POST /activiti-app/api/runtime-instance

{    "message":"myMessage",    "variables": [       {         "name":"myVar",         "value":"This is a variable",       }    ] }

Alternatively, if you are using the Java API use:

ProcessInstance startProcessInstanceByMessage("myMessage");

If you are looking for a complete example using java code, take a look at 

MessageStartEventTest.java in the Activiti source Activiti/MessageStartEventTest.java at activiti-5.22.0 · Activiti/Activiti · GitHub 

Look for "testingSingleMessageStartEvent" test.

Hope this helps,

G

arag
Confirmed Champ
Confirmed Champ

Thanks!!! you save my life Smiley Happy