@Helene Hello Helene,
I want to do the following:
I have a Message Event and at the moment I am sending message with post man but I want to create a POST in Spring Boot and the result that some other application sends me via this POST I want to receive it in the Message Event. At the moment I am using the Camunda build in POST event “/rest/message” but I will create my own but I am not sure how to connect my POST with the Message Event. Can you give me some hint?
I’m not very familiar with this, but if I am understanding you correctly you are asking about how to correlate the message in the engine, right? You can add information in the request body for the correlation, for example a businessKey, processInstanceId, tenantId, or even variables. Hope that helps.
@hahi If i understood correctly, with or w/o small modifications you want to redirect the post request from the client application to the camunda message event(POST /rest/message) right?
Yes that is correct. I have Post Service updateMoney() in Spring boot which will activate the camunda message event(POST /rest/message). And this Post Service updateMoney() will be called in another application.
@hahi Okay. It seems you’re providing wrapper around camunda message event(POST /rest/message) or maybe a facade, anyway you’ve already defined the api contract which will internally triggers message event. So you can share that api contract to the client application.
I dont really understand you.
I have my application A. It has Post Service updateMoney() in Spring boot.
This updateMoney(iban, money) will be called in another application B.
When application B call it then I need to get the iban and money and trigger the correct message that is waiting this means I need the BusinessKey which the application B does not have.
And I am not really sure how to do the code. I did the POST for method updateMoney() but after that how to connect it with the camunda message event(POST /rest/message) I am not sure.
You can also do as @Helene suggested and just correlate the message against the process variable. The business key is most often used, but it’s not actually required.
In the JSON that you posted there is a BusinessKey, which corresponds for the particular process and in this way camunda understands which message to trigger. If I have 10 messages waiting without BusinessKey how will I do it?
Businesskey is optional, If the process instance has process variables like iban, money, etc. you can use the variables to correlate to that message event.
I understand you, but if there are 10 processes running and when you open in camunda Cockpit in the Message Event there will be 10 waiting. And if you call the method as you said then how Camunda will understand for which process to trigger the message. Because every process will be triggered from different people. There should be something unique like BusinessKey but I cant get it from the caller(the app which will call my external service). hm…
Yes it is, but I dont have it at that point in my DB. I will have it in the main application but in the Camunda application I wont have it. Well what is your idea actually?
Hi @hahi
It’s very hard to try to explain a solution with giving you a basic understanding of how message events work. So i suggest if you don’t want to read the docs that @Helene post up earlier you can watch this tutorial: 7 Tutorial: Process Communication - YouTube
After you’ve understood messages a little more, feel free to follow up with any other questinos.
@Niall this is not true I did it till here but this is the Controller… I dont have the businessKey and I know how messageEvent works. Niall I was doing before exactly what you do in the tutorial but I dont want postman… I want somehow to get the exact correlation message for the particular business key… maybe I need to save something in the db … I will think about thank you guys…
@RestController
@RequestMapping("/dawdawdaw")
public class AdsasdRestController{
private final Logger logger = LoggerFactory.getLogger(AdsasdRestController.class);
private final RuntimeService runtimeService;
@Autowired
public AdsasdRestController(RuntimeService runtimeService) {
this.runtimeService = runtimeService;
}
@PostMapping(value = "/dawdawdaw", consumes = MediaType.APPLICATION_JSON_VALUE)
void addAdwawd(@RequestParam("aaaa") String aaaa, @RequestParam("bbbb") String bbbb) {
runtimeService.createMessageCorrelation("dawdawdaw")
.processInstanceBusinessKey() <-- I dont have it how to start it
.setVariable("bb", bbbb)
.setVariable("aa", aaaa)
.correlateWithResult();
}
}
EDIT: I changed this post in order to highlight the code better -Niall
@hahi You can check this example for usage of message start event and message intermediate boundary event, and how it’s been correlated without businesskey.
@Slf4j
@Component("orderReturnDelegate")
public class OrderReturnDelegate implements JavaDelegate {
@Override
public void execute(DelegateExecution execution) throws Exception {
log.info("Reason for cancelling the order: {}", execution.getVariable("cancelReason"));
}
}
Can you execute on your example 10 times the process and leave all processes to wait on the message event and then execute this JSON that you showed me. I wanna see what will happen. How Camunda will execute what you want. Because I have different people who will start the process and for every person you will have different IBANs. So how will you know which message to trigger? BEcause process 1 can have IBAN 123 and process 2 can have IBAN 234 and you just will send random IBAN 123 to process 2 which does not have this IBAN 123 but has IBAN 234. Did you understand my problem? I understand very well what you do.