How to implement Timertask along with a Receive Task

Here is my process.

After sending messages to external systems, the process should wait at the Receive Task. There should be a polling mechanism within the Receive Task that should check an external system for a particular status ,say accepted = true (This can be done by invoking a REST call). So that I can trigger the message event from the receive task itself to end the process. Is this the right pattern??? can someone help me with a small code snippet for this. I know my requirement is somewhat close to the below post. However I find it difficult to implement it.

@prasadps if you are “polling” then using the Receive (waiting for response) task will not be what you are looking for.

Is this is the design you want, I would suggest you create another process that polls and messages your Waiting Response task based on a unique message.

Sure. …You can suggest …

@prasadps

Maybe you are looking for something like that?

regards,
Dominik

This looks good …however i dont find an option in camunda modeller to create a timer task :pensive:

sorry got it…Thanks:)

I have implemented the above diagram. however the message end event is not sending message to the receive task even though they both have the same message reference. So the process doesn’t end.

They both refer to the below message.
attachment.txt (413 Bytes)

(Right now I have implemented this with the help of an execution listener attached to the message end event. Within the listener I send messages to the receive task see the code below)

RuntimeService runtimeService = execution.getProcessEngineServices().getRuntimeService();
String processInstanceId = execution.getProcessInstanceId();
Execution execId = runtimeService.createExecutionQuery()
.processInstanceId(processInstanceId).activityId(“waitState”).singleResult();
LOGGER.info("ProcessInstnace Id : "+ processInstanceId +“ExecutionId :” + execId);
EventSubscription subscription = runtimeService.createEventSubscriptionQuery()
.processInstanceId(processInstanceId).eventType(“message”).singleResult();

   	runtimeService.messageEventReceived(subscription.getEventName(), subscription.getExecutionId())

Hi @prasadps,

To correlate a message with the instanceId in Java you should do the following:

runtimeService.createMessageCorrelation(“YourMessageName”).processInstanceId(instance.getId()).correlate();

regards,
Dominik :slight_smile:

The code I have implemented within the listener is working fine. What doesn’t work is the message end event. I want to get rid of the listener implementation (i added listener coz the message end event is not serving it’s purpose). This would help business to configure from the notation itself. I want the message end event to communicate with the receive task without the help of listener.

Hi @prasadps,

take a look at that discussion Correlate Message directly from message event
It isn’t possible to correlate the message without some lines of code.
But you could create a global executionListener that correlates the message to its processInstance if there are any receive message tasks/events.

regards,
Dominik