# Recieve Task in flowable is not working propelly

**URL:** <https://forum.flowable.org/t/recieve-task-in-flowable-is-not-working-propelly/5302>\
**Category:** Flowable Engine\
**Created:** [January 26, 2020, 3:50pm UTC](https://forum.flowable.org/t/recieve-task-in-flowable-is-not-working-propelly/5302 "2020-01-26T15:50:53Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![gihan](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/gihan/32/1803_2.png) [@gihan](https://forum.flowable.org/u/gihan)\
**Post date:** [January 26, 2020, 3:50pm UTC](https://forum.flowable.org/t/recieve-task-in-flowable-is-not-working-propelly/5302/1 "2020-01-26T15:50:53Z")

</div>

while running business process and getting the execution of receive task it throws “exection is not found”

```
    List<Execution> executionList=runtimeService.createExecutionQuery().processInstanceId(trigger.getProcessInstanceId()).list();

```

runtimeService.trigger(executionId,varList);

please note that if wait(time) it return result successfully

any one have answer why the execution is not found without waiting

---

<div class="post-metadata">

**Author:** ![wwitt](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/wwitt/32/706_2.png) [@wwitt](https://forum.flowable.org/u/wwitt)\
**Post date:** [January 26, 2020, 6:13pm UTC](https://forum.flowable.org/t/recieve-task-in-flowable-is-not-working-propelly/5302/2 "2020-01-26T18:13:16Z")

</div>

Flowable uses database transactions to isolate events from each other and ensure consistency. This means that in workflows that initiate a process outside of Flowable and awaits a response can run into issues if the response happens too quickly. The solution is usually to move the request to the external system outside of the commit transaction context. This is done with a transaction listener as follows:

```auto
Context.getTransactionContext().addTransactionListener(TransactionState.COMMITTED,
    commandContext -> {
        someService.someMethod();
    });

```

Additionally, the “send a message with a service task and then have a receive task to accept the response” pattern is so common, we have a “triggerable service task” that can encapsulate both steps in the process.

---

<div class="post-metadata">

**Author:** ![gihan](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/gihan/32/1803_2.png) [@gihan](https://forum.flowable.org/u/gihan)\
**Post date:** [January 29, 2020, 9:12am UTC](https://forum.flowable.org/t/recieve-task-in-flowable-is-not-working-propelly/5302/3 "2020-01-29T09:12:14Z")

</div>

Thanks alot for your reply

should this code be exist in service task before receive task  
Context.getTransactionContext().addTransactionListener(TransactionState.COMMITTED,  
commandContext -\> {  
someService.someMethod();  
});

or where we can use this code

---

<div class="post-metadata">

**Author:** ![wwitt](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/wwitt/32/706_2.png) [@wwitt](https://forum.flowable.org/u/wwitt)\
**Post date:** [January 29, 2020, 12:26pm UTC](https://forum.flowable.org/t/recieve-task-in-flowable-is-not-working-propelly/5302/4 "2020-01-29T12:26:29Z")

</div>

Yes, the transaction listener should exist in the task before the receive task. It should only contain the code that actually sends the message or contacts the external process.

Here was another post with a similar issue:

> [@Asynchronous Service Invocation using Flowable](https://forum.flowable.org/t/asynchronous-service-invocation-using-flowable/5207):
>
> In Flowable documentation: "When the external service wants to trigger the waiting process instance again, this can be done synchronously and asynchronously. To prevent optimistic lock exceptions, the asynchronous trigger would be the best solution. By default an async job is exclusive, which means that the process instance will be locked and it’s guaranteed that no other activity on the process instance can interfere with the trigger logic.” But we are faced with the fact that the behavior …

---

<div class="post-metadata">

**Author:** ![eslam](https://avatars.discourse-cdn.com/v4/letter/e/67e7ee/32.png) [@eslam](https://forum.flowable.org/u/eslam)\
**Post date:** [January 29, 2020, 3:15pm UTC](https://forum.flowable.org/t/recieve-task-in-flowable-is-not-working-propelly/5302/5 "2020-01-29T15:15:46Z")

</div>

Thanks a lot, wwitt!  
how can i throw Bpmn error inside the transaction listener(in case failed to sending message)

---

<div class="post-metadata">

**Author:** ![wwitt](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/wwitt/32/706_2.png) [@wwitt](https://forum.flowable.org/u/wwitt)\
**Post date:** [January 30, 2020, 2:31am UTC](https://forum.flowable.org/t/recieve-task-in-flowable-is-not-working-propelly/5302/6 "2020-01-30T02:31:17Z")

</div>

That’s an excellent question, once a transaction is committed it would not be able to be rolled back.  
How likely is it that you would fail sending a message? Perhaps @joram or one of the other devs with a bit more experience can offer some advice.

---

<div class="post-metadata">

**Author:** ![wwitt](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/wwitt/32/706_2.png) [@wwitt](https://forum.flowable.org/u/wwitt)\
**Post date:** [January 31, 2020, 12:09pm UTC](https://forum.flowable.org/t/recieve-task-in-flowable-is-not-working-propelly/5302/7 "2020-01-31T12:09:19Z")

</div>

After some discussion, I think your best bet is use `TransactionState.COMMITTING` if you need to handle errors. This will ensure that message send is the last thing that happens before commit, greatly reducing the likelihood that a message would come back before the the execution was ready to be triggered. You would still need some logic that handles the received message gracefully in case it comes back too soon.

---

<div class="post-metadata">

**Author:** ![eslam](https://avatars.discourse-cdn.com/v4/letter/e/67e7ee/32.png) [@eslam](https://forum.flowable.org/u/eslam)\
**Post date:** [February 2, 2020, 9:13am UTC](https://forum.flowable.org/t/recieve-task-in-flowable-is-not-working-propelly/5302/8 "2020-02-02T09:13:09Z")

</div>

Thanks a lot, wwitt!

---

<div class="post-metadata">

**Author:** ![joram](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/joram/32/26_2.png) [@joram](https://forum.flowable.org/u/joram)\
**Post date:** [February 4, 2020, 8:19pm UTC](https://forum.flowable.org/t/recieve-task-in-flowable-is-not-working-propelly/5302/9 "2020-02-04T20:19:01Z")

</div>

> [@wwitt](#):
>
> That’s an excellent question, once a transaction is committed it would not be able to be rolled back.

Correct. One way to solve it, is to use JTA transactions (which is heavyweight for this kind of thing).  
The engine doesn’t have anything out of the box to do this, but one option could be to create a timer job (in a new transaction) to retry the message sending at a later point in time.
