Access the process engine name

Hi all

The class ProcessEngines provides a method getProcessEngine(String name):

org.camunda.bpm.engine.ProcessEngines.getProcessEngine(String)

How do I retrieve the name of the process engine, I am currently in, so that I can pass it to getProcessEngine(String)?

I want to call this method within an ExecutionListener.

Thank you.

Hi @miguelgalaxy

There is a method getProcessEngineInfos() can find more details here. The individual List object contains a method getName() documented here. It returns the process engine name.

If you re in default process engine then can use ProcessEngines.getDefaultProcessEngine().getName()

Hi @miguelgalaxy

If you didn’t define more than one process engine then It is better to use getDefaultProcessEngine() method to get the only one default process engine you have.

The process engine configuration can be placed in both processes.xml and the bpm-platform.xml files (See below link)
https://docs.camunda.org/manual/7.4/reference/deployment-descriptors/tags/process-engine/

On way to achieve Multi-Tenancy is by providing one process engine per tenant (See below link)
https://docs.camunda.org/manual/7.5/user-guide/process-engine/multi-tenancy/#one-process-engine-per-tenant

By the way, in case you are looking to access ProcessEngineServices from ExecutionListener like (HistoryService, IdentityService, ManagementService, TaskService …) then, better to get it as below

execution.getProcessEngineServices().

getHistoryService()
or getIdentityService()
or getManagementService()
or getRepositoryService()
or getRuntimeService()
or getTaskService()

@hassang
@Vinodlouis
Thank you for your replies.

I have a setup with multiple process engines (https://docs.camunda.org/manual/7.5/user-guide/process-engine/multi-tenancy/ => One Process Engine per Tenant).

I don’t use the default process engine.

How do I retrieve the name of the process engine in such a setup?

Hi @miguelgalaxy

May we know the use case of getting the current process engine object?

Hi @miguelgalaxy

One such example can be seen multi-tenancy.md#make-cdi-injection-tenant-aware. This might help you

@hassang

Sure.

I want to use the History REST API in an embedded form.
https://docs.camunda.org/manual/7.5/reference/rest/history/

There, I need to pass the name of the engine as a parameter (/engine/{name}).
https://docs.camunda.org/manual/7.5/reference/rest/overview/#engine-usage

In the end, I need to know the name of the process engine in java script so that I can make a REST API call from there.

Hi @miguelgalaxy

You can get the tenantId from embedded form using the available built-in variable camForm as follow

var processDefinitionService = camForm.client.resource('process-definition');
processDefinitionService.get(camForm.processDefinitionId, function(err, processDefinition) {
    	alert(processDefinition.tenantId);
});

@hassang

Thank you.

But instead of the tenantId I need the process engine name.

When I bootstrap a process engine, then I use this statement to set the process engine name:

org.camunda.bpm.engine.ProcessEngineConfiguration.setProcessEngineName(String)

Hi @miguelgalaxy
Try to get tenant name as follow. Suppose it has same name as the process engine’s name; otherwise you can edit tenant attributes from admin app (See below link)

https://docs.camunda.org/manual/7.6/webapps/admin/tenant-management/

var processDefinitionService = camForm.client.resource('process-definition');
var tenantService = camForm.client.resource('tenant');
processDefinitionService.get(camForm.processDefinitionId, function(err, processDefinition) {
    	tenantService.get(processDefinition.tenantId, function(err, tenant) {
    	alert(tenant.name);
});
});

Hi @hassang

Thank you for your reply.

This sounds like a workaround to me, because I have to create a tenant within each process engine, even if I don’t need a tenant.

If there is no other solution, then I will try you suggestion.

I haven’t really followed the discussion, but the answer to your original question

would be: There does not seem to be an API. It appears you can write something like ProcessEngine engine = (ProcessEngine) execution.getProcessEngineServices(); though, where execution is an instance of DelegateExecution. Of course that cast is not safe and may not work in future versions. Feel free to raise an issue in our JIRA to expose a proper API for that and/or create a pull request.

Cheers,
Thorben

1 Like

@thorben

Thank you for you reply. This solves my problem.
I will open a JIRA issue so that this workaround becomes a public API.

Regards