How can I read the Correlating Message from java code

Hi All

I have the below event-driven architecture in a distributed environment where I’m sending a command to get user payment details (Query) from the user service and in the next task I need to get from java code those user payment details to process payment adapter delegate.

Kindly advice how to get the Correlating Message of the user details from the process payment adapter using java code ?

Best Regards

image

Hello my friend!

If you are using JavaDelegate you can do something like this:

        execution.getProcessEngineServices().getRuntimeService()
                .createMessageCorrelation("messageName")
                .processInstanceId(execution.getProcessInstanceId())
                .setVariable("variableName", objectValue)
                .setVariable("otherVariableName", objectValue)
                .correlate();

In setVariable you can pass the name you want for the variable that will store these “details” in your process and its value.

NOTE: You can chain multiple setVariables.

I hope this helps!

William Robert Alves

Thanks for you reply;

I was able to read the JacksonJsonNode however I’m not able to get the value in java:

org.camunda.spin.impl.json.jackson.JacksonJsonNode jsonNode = {“firstName”:“test1”,“lastLame”}

Which method to use to get the values?

jsonNode.get(“fisrtName”) is not available?

Best regards

Hello @zidoff

Why are you using SPIN? Would it be an option to use a JavaDelegate instead (which maybe would be easier)?

BR
Michael

Hello @zidoff !
If you are using SpinJson, you should do this in your case:

String firstName = jsonNode.prop("firstName").stringValue();

William Robert Alves

Hello @zidoff !

Here at the company we have a Camunda project that orchestrates microservices and uses SpinJson, this is because the company people didn’t like Java and we do all the code internally within Camunda’s own tasks, without external code files. :hot_face: :sweat_smile:

but I particularly love Java… and if it were up to me, all my projects would be with Camunda embedded with spring / Java / JavaDelegates.

William Robert Alves

1 Like

Hello @zidoff @WilliamR.Alves

Yeah, that’s why I was asking about using the Spin plugin. If it’s because you don’t want to do Java, then that’s fine, but I think a better alternative to using Spin / scripts is then to use the external task pattern and choose a programming language that you like and which is supported by your organization.

Personally I am not a big fan of the Spin / script setup and I would also prefer a Java setup like the one William describes :slight_smile:

BR
Michael

1 Like

Hello my dear @mimaom !

Both can be used together, and serve different purposes.

For example, in a microservices orchestration project, you may need to use Spin more.

When we use external tasks, processing occurs outside the camunda engine, returning a success or failure response, serves for asynchronous processing.
Spin, on the other hand, basically works with input data processing… for example, you can access an API with an http-connector, and receive the response… from this response you can assemble payloads to pass as input data to the next microservice you will call.

But without a doubt, the fact that we can use any language with external tasks is what makes external tasks so widely used! Thank you for helping to share knowledge \o

William Robert Alves

Hello @WilliamR.Alves

Thank you for your input.
I agree that different styles suit different needs / preferences. I would still choose the external task pattern over Spin / script - also for microservice orchestration. But that really is more of a personal preference :slight_smile:

Have a nice weekend.

BR
Michael

1 Like