Java code implementation on service task not executing from the first process instance but from the second one


process.bpmn (12.8 KB)

I basically have a process instance that when it gets to Send Request service task, a java class code should execute to send a post request containing messageName which would help the Event Gateway to redirect the instance.
But what i noticed is that when i create the first process instance nothing happens and it get stuck on gateway, but when other processes after they all work normally, i faced this issue before on previous project and i fixed it by turning Asynchronous Before on, but for some reason this solution not working now. Any help would be appreciated. Thank you in advance.

Hi @hadi_hoteit,

a process instance cannot send a message that should be picked up in a receive event that follows later in the process.

Reason: The message receive event needs to be saved in the database before the message is correlated.

That also explains why it worked in the second process instance: the message is delivered to the first instance.

What do you want to achive? Maybe a different event type is needed or you can switch to the external service task and implement the logic in the worker an react in the process model on the result.

Hope this helps, Ingo

2 Likes

Hi @hadi_hoteit,

Using exchanging messages approach to do communications within the same pool is not a good practice (should be avoided).

As @Ingo_Richtsmeier said, It would be great if you can explain your needs so we can suggest a better solution.

Thank you so much for the explanation, I now understand better the problem.
But I’m trying to automate the whole process, I want a POST request to be sent as soon as the process instance reaches the Event Gateway, but you cannot add Implementations for java classes or connectors or externals to Gateway, which is why i put a task before it and added it to the task, hoping if i changed the Asynchronous Before on the task it would work, but it didn’t.
Any ideas on how i can manage to achieve automatically sending POST request when instance gets to gate?
Thank you again.

Hi @hadi_hoteit,

Using event based gateway followed by two catching intermediate messages means that execution token would be waiting at the gateway until any of the following messages get received from the external world. (not from within the same process)

Hi @hadi_hoteit,

Why not to use an exclusive gateway to decide which flow to follow based on a process variable’s value instead of using event based gateway with messages?

Can you please elaborate more…

Hi @hassang ,

I am still new to Camunda so I was doing random ideas and projects to learn from them. So there is no actual goal to my project i was just trying to get familiar with some of the tasks and gateways and i thought it would be interesting if I automated the whole process.
I never knew that exclusive gateway can do that since I still haven’t used it before, like I said I’m still learning, I guess using exclusive gateway would be optimal for my case, so I’ll switch my gateway to it, Thank you again for informing me.

Do you mind telling me a few more interesting subject in your opinions for me to do as a project to learn from? Anything new would enlighten my Camunda knowledge (I’ve only worked with the tasks and gateway you see in the image i send before so I’m missing a lot of knowledge).

Thank you again Hassan

Hi @hadi_hoteit,

You can familiarize yourself with bpmn symbols. Below is a good starting point

For more advanced modeling guidelines, you can have a look at

https://camunda.com/best-practices/building-flexibility-into-bpmn-models/

1 Like

That’s just what i needed, thank you so much for helping. :smiley:

1 Like