Camunda Platform 8 - Receive Task

Hello, I’m new to Camunda 8 and I’m trying to configure a Receive Task with a simple BPMN model showed below:

I was able to use the Send Task by following the steps described here:

Currently, I have this Java project working, then, I tried to add the code to use the ReceiveTask and I ended up with my code like this:

package io.camunda.getstarted.tutorial;
import java.util.HashMap;
import java.util.Map;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import io.camunda.zeebe.client.api.response.ActivatedJob;
import io.camunda.zeebe.client.impl.ZeebeClientBuilderImpl;
import io.camunda.zeebe.client.impl.oauth.OAuthCredentialsProvider;
import io.camunda.zeebe.client.impl.oauth.OAuthCredentialsProviderBuilder;
import io.camunda.zeebe.client.ZeebeClient;
import io.camunda.zeebe.spring.client.EnableZeebeClient;
import io.camunda.zeebe.spring.client.annotation.ZeebeWorker;

@SpringBootApplication
@EnableZeebeClient
public class Worker {
  private static final String zeebeAPI = "fbe78958-209f-4daa-8278-3d81bf161e06.bru-2.zeebe.camunda.io";
  private static final String clientId = "z5jW~eX.ShwRx7G1S5pBmUEZW-a4wMdk";
  private static final String clientSecret = "ClientSecret";
  private static final String oAuthAPI = "https://login.cloud.camunda.io/oauth/token";
  ZeebeClient client;

  public static void main(String[] args) {
   
    SpringApplication.run(Worker.class, args);
  }
  
  @ZeebeWorker(type = "orchestrate-something", autoComplete = true)
  public Map<String, Object> orchestrateSomething(final ActivatedJob job) {
      // Do the business logic
      System.out.println("Yeah, now you can orchestrate something :-) You could use data from the process variables: " + job.getVariables());

      // Probably add some process variables
      HashMap<String, Object> variables = new HashMap<>();
      variables.put("orderId", 42);
      
      OAuthCredentialsProvider credentialsProvider =
      new OAuthCredentialsProviderBuilder()
          .authorizationServerUrl(oAuthAPI)
          .audience(zeebeAPI)
          .clientId(clientId)
          .clientSecret(clientSecret)
          .build();

      ZeebeClient client =
      new ZeebeClientBuilderImpl()
              .gatewayAddress(zeebeAPI)
              .credentialsProvider(credentialsProvider)
              .build();
  
       client.newTopologyRequest().send().join();

       client
         .newPublishMessageCommand()
         .messageName("Money-collcted")
         .correlationKey("123")
         .send()
         .join();
     
        return variables;
  }

}

But when I execute a process instance, I can execute the SendTask, but the token keeps waiting on the ReceiveTask =( When I look at the terminal, I get no error, only the expected print “Yeah, now you can orchestrate…”:

I also tried to use the zbctl to publish the message. I tried using the following command:

zbctl publish message “Money-collcted” --correlationKey “order-123” --address “fbe78958-209f-4daa-8278-3d81bf161e06.bru-2.zeebe.camunda.io:443” --clientId “z5jW~eX.ShwRx7G1S5pBmUEZW-a4wMdk” --clientSecret “clientSecretValue”

And I got the response with a key, for example:

{
“key”: “1234322432”
}

Which I think means the message was published succefully, But the instance still keeps stopped at the the ReceiveTask.

Can somebody tell me what I am doing wrong?

Here are the prints when I try to use the zbctl

Hello @Matheus_Pereira_de_A ,

the secret here is the correlation key.

In your example, it is your orderId, which is set to 42 in your code snippet.

Then you try to correlate to „123“, which will not work.

Both values need to to fit, so either set orderId to „123“ or your correlation key to 42.

I hope this helps.

Jonathan

3 Likes

Nailed it!

This blog post goes into detail on message correlation: Zeebe Message Correlation - Camunda

Josh

2 Likes

oh I can’t believe it worked! I’ve been stuck in this problem for like a week! Thank you so much.

1 Like

Thank you for the very detailed description :wink: this helped us (the community) to provide the best help!

I don’t know if I should open other question for this or no. But now I’m trying to model a process with 2 pools representing a client and a bank. I’m trying to send a message from the client to the bank, but for some reason the message isn’t being delievered to the bank, here’s how it is:

Both pools are checked as executable and in the message start event, I’m using the same Name as in ReceiveTask, but with no correlation key

I also deleted the receive task from the first pool to check if the problem was that i was consuming twice the message, but that didnt solve the problem =(

Hello @Matheus_Pereira_de_A ,

could you please create a new thread on this? I can then provide the answer :wink:

Jonathan

Ok, I’ll do it.