I have a design question regarding reactive programming. I have a service that returns a Mono<>
object (in the background, it calls an endpoint of another service), and I’d like to handle it in a reactive way to avoid ‘killing’ the idea with a block()
function. Is this solution an acceptable way to handle it (I’d like to put the created object into variables for further processing), or will I run into various problems like concurrency and so on?
@JobWorker(type = "persistOneEntityWorker", autoComplete = false)
@SuppressWarnings("unused")
public void persistOneEntity(final JobClient client, final ActivatedJob job) {
Map<String, Object> variables = job.getVariablesAsMap();
OneEntity oneEntity = new OneEntity(Long.toString(job.getProcessInstanceKey()), "body one camunda");
oOneService.createOneEntity(oneEntity)
.subscribe(created -> variables.put("oneEntity", created),
error -> {
throw new RuntimeException("Could not complete job " + job, error);
},
() -> {
client.newCompleteCommand(job.getKey())
.variables(variables)
.send()
.exceptionally(throwable -> {
throw new RuntimeException("Could not complete job " + job, throwable);
});
logger.debug("PersistOneEntity system task {} completed!", job.getKey());
});
}