How to send a message from a Service Task to a Message Start Event

Hello to every body.
I’m new in this forum, I’have started to use Camunda from 4 days and I have a question.
I have this situation:
ImgCustom
I have a service Task, in the picture the service A, that receive a object from another service and its has to sent the object to a Start Service Task, in the picture the B, the service task, one time received the message, has to take the object and send its to the task connected.
How can I do its by Java?.
I would like to use a message, and I studied on the documentation to use:

// correlate the message
MessageCorrelationResult result = runtimeService.createMessageCorrelation(“messageName”)
.processInstanceBusinessKey(“AB-123”)
.setVariable(“payment_type”, “creditCard”)
.correlateWithResult();

If use the code above is the right thing to do, I hadn’t been able to configure the event to recieve the message.
I configure the the delegate service A to send a message with the following code:

execution.getProcessEngineServices()
.getRuntimeService()
.createMessageCorrelation(“createConferece”)
.setVariable(“confercenceData”, conferenceData)
.correlateAll();

I would like to know how to configure the start event.
I hope that somebody helps me.
Best Things
Alessandro

Hi Alessandro,

Could you please share you processes.

Best regards,
Yana

Hello Yana Vasileva,
thanks a lot for your reply,
of course, this’s my process:


In the ServiceTask in Read, I added the follow code:

  ConferenceData conferenceData = (ConferenceData) execution.getVariable("conferenceDataObj");
			execution.getProcessEngineServices()
			.getRuntimeService()
			.createMessageCorrelation("createConferece")
			.setVariable("conferenceObj", conferenceData)
			.correlateAll();
			LOGGER.info("--- object conferenceData sent ---");

I would like to catch the message message = ‘createConferece’ and the object = ‘conferenceData’ in the MessageStardEvent in Blue.
One time took the object I would like to send all to the ServiceTask in greed.
I hope that you can help me.
I also thought to change the start process in blue in a ReciveTask and the and the serviceTask in red in a SendTask, do you think that is better for the process?
Best regards,
Alessandro

@alerappo93 have you set your Message start event with the message name “createConference” ?

Hello StephenOTT
thanks a lot for your reply,
I added the following setter:


Is the right thing to do?
Best regards,
Alessandro

Yes. Here is a simplified example that shows the flow working.

1 Like

Thanks a lot for your reply,
you are really kind.
But, in my process in camunda it doesn’t work?
Do you know you?
Best regards,
Alessandro

Is there a error in terminal?

Thanks a lot for your reply,
no nether one,
Nothing happen in the terminal.
It’s look like it’s work normally!
Alessandro

Can you log the result of your correlation attempt and see what the returned value is

Hello
I changed the method from correlateAll() to .correlateWithResult();
Now in my ServiceTask my code is:

try {
ConferenceData conferenceData = (ConferenceData) execution.getVariable(“conferenceDataObj”);
execution.getProcessEngineServices()
.getRuntimeService()
.createMessageCorrelation(“createConferece”)
.setVariable(“conferenceObj”, conferenceData)
.correlateWithResult();
LOGGER.info("— object conferenceData sent —");
}catch (Exception e) {
LOGGER.warning(“ERROR CustomerCreateConferenceDelagate ->” + e.getMessage());
}

and i got a error in my console:


I have configurate my MessageStardEvent using the camunda modeller in the following way:

I really hope that you can help me.
thank a lot for you time.
Best regards,
Alessandro

I’m wrong, because i don’t need a result. I only want send a message.
I think that i have to use .correlateAll();

Can you post your BPMN file?

2 Likes

hello StephenOTT,
sorry for my late, i will.
I wold like to change my bpms in something like:


In the send task I set the following class:

@Override
public void execute(DelegateExecution execution) throws Exception {
try {
ConferenceData conferenceData = (ConferenceData) execution.getVariable(“conferenceDataObj”);
execution.getProcessEngineServices()
.getRuntimeService()
.createMessageCorrelation(“createConferece”)
.setVariable(“conferenceObj”, conferenceData)
.correlateAll();
LOGGER.info("— object conferenceData sent —");
}catch (Exception e) {
LOGGER.warning(“ERROR CustomerCreateConferenceDelagate ->” + e.getMessage());
}
}

in the received:
image
and send the task at the class prova with the class:

public void execute(DelegateExecution execution) throws Exception {

LOGGER.info("\n\n  ... LoggerDelegate invoked by "
        + "processDefinitionId=" + execution.getProcessDefinitionId()
        + ", activtyId=" + execution.getCurrentActivityId()
        + ", activtyName='" + execution.getCurrentActivityName() + "'"
        + ", processInstanceId=" + execution.getProcessInstanceId()
        + ", businessKey=" + execution.getProcessBusinessKey()
        + ", executionId=" + execution.getId()
        + " \n\n");

}

}

I really can’t understand why its doesn’t work.
Do you have any idea?
Thank you so much for your time
Best regards,
Alessandro

You should have a message start event. Not a receive task

Hello @alerappo93 ,
Could you please post your github repo for your example.
Thank you