Get the Message Name for a message Event

340 views
Skip to first unread message

Niall Deehan

unread,
Jan 21, 2016, 7:57:44 AM1/21/16
to camunda BPM users
Hi Folks,

While a message throw event is being modeled, it contains the message name it will be sending. I already have some code which can send the message but i'd like to be able to read the name of the message from the model itself before creating it.
The idea being that if the name of the message is changed on the model i wouldn't need to update the code.

Any idea's on how in run time i'd be able to get the message name of a message event I'm currently waiting at?

Thanks!
Niall

thorben....@camunda.com

unread,
Jan 21, 2016, 10:35:52 AM1/21/16
to camunda BPM users
Hi Niall,

In case you implement the throwing message event with a JavaDelegate, you are handed a DelegateExecution object. DelegateExecution has a method #getBpmnModelElementInstance that returns the current activity in the BPMN model as represented by the camunda bpmn model api. For a throwing event, you can cast the return FlowElement to IntermediateThrowEvent and from that it should be possible to access the event definition and the message name. Please let me know if you need a code snippet for that.

Cheers,
Thorben

Niall Deehan

unread,
Jan 22, 2016, 3:20:44 AM1/22/16
to camunda BPM users
Thanks for that Thorben,

So, i'm not actually trying to get it from a JavaDelegate, but i am using an execution listener which runs a groovy script.
This at least means that i do have access to the execution so i can still do something like this:

 IntermediateThrowEvent misterMesssageThrow = (IntermediateThrowEvent) execution.getBpmnModelElementInstance();

my next question is - how exactly do i find the messageName from the misterMessageThrow variable. there doesn't seem to be a method that gives me direct access to the message name itself.

Thanks!

Sebastian Menski

unread,
Jan 22, 2016, 4:18:30 AM1/22/16
to camunda BPM users
Hi Niall,

if there is only one EventDefinition this should work:

IntermediateThrowEvent throwEvent = (IntermediateThrowEvent) execution.getBpmnModelElementInstance();
MessageEventDefinition eventDefinition = (MessageEventDefinition) throwEvent.getEventDefinitions().iterator().next();
Message message = eventDefinition.getMessage();
String messageName = message.getName();

Cheers,
Sebastian
Reply all
Reply to author
Forward
0 new messages