How to publish a single event to continue a running instance using NextJS

What our problem?
Publishing an event is sometime don’t triggering the workflow to continue.

What language are we using?
NextJS using @camunda8/sdk

Our BPMN flow
Using the lanes to show the interaction between UI & Backend. This is not a real world application, but more to learn how to work with events in Camunda, allowing the process to “wait” for external system to trigger - “continue please”

Code snippet

The code below is how we “signal” the process to continue.

    this.getZeebeInstance().publishMessage({
      correlationKey: `${orderId}`,
      name: "aproved-order",
      timeToLive: 0,
      variables: {
        status: "approved",
      }
    });

Why timeToLive:0?
We want to ensure that only a single [yes please continue] are allowed. Would this impact our use-case, and is this the reason why we sometimes get stuck at the event not processed?

Hello, @oegma2

The issue of race conditions occurs when the sender of a message sends it before Camunda is prepared to receive it.

In order to prevent this situation, Camunda 8 introduced message buffering feature. Therefore, it is necessary to set a TTL (Time-to-Live) value that ensures the absence of such a problem.

https://docs.camunda.io/docs/components/concepts/messages/#message-buffering

Thanks for the response @hassang.

I updated the TTL to 30 seconds and now it works correctly with small load.

Started a JMeter script with 10 users calling the API and ended up one call didn’t complete and waited for the event and eventually throw this error message

23:16:50.827 | zeebe | ERROR: [createProcessInstanceWithResult]: 8 RESOURCE_EXHAUSTED: Expected to execute the command on one of the partitions, but all failed; there are no more partitions available to retry. Please try again. If the error persists contact your zeebe operator

It might be how I make the call

Provided a section that handling the Collect Money worker and then also signals the Approved Order event.

console.log(`[Zeebe] Creating worker for collect-money-service-task`);
this.getZeebeInstance().createWorker({
  taskType: 'collect-money-service-task',
  taskHandler: (job) => {
    // Create a unique process ID
    const orderId = uuidv4();
    console.log(`[Zeebe Worker] {collect-money-service-task} - Handling request for: ${orderId}`);

    // <<< DO WORK HERE >>>
    const totalAmount = 1000;

    // Signal the completion of the job
    var result = job.complete({
      message: `Money collected for ${orderId} completed successfully.`,
      totalAmount: totalAmount,
      orderId: orderId,
      status: "completed",
    });

    // Publish a message to the message broker to continue the process (can be from outside the process too)
    this.getZeebeInstance().publishMessage({
      correlationKey: `${orderId}`,
      name: "order-approved",
      timeToLive: 30,
      variables: {
        orderId: orderId,
        totalAmount: totalAmount,
        status: "approved",
      }
    });      

    return result;
  },
});

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.