Where is the best place to set variables globally to be used across different bpmn files

I would like to set variables globally, and all these variables are stateless.
For example, I would like to set URL’s globally only once for the entire spring boot camunda application.
Right now the below code executes for every single request, as below variables are stateless, I would like to set these variables only ONCE

Here is the sample code which we are using it now, but would like to refactor

     ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();
            ProcessInstantiationBuilder instance = engine.getRuntimeService().createProcessInstanceByKey("create-template");
     instance.setVariable("URL1","https://google.com");
     instance.setVariable("URL2","https://forum.camunda.io");
    ProcessInstanceWithVariables response = instance.executeWithVariablesInReturn();

refactored above code, which is not working how I expected, this where I would need help from community
I would like to set those variables on application start up

@Bean
    public RuntimeService setGlobalVariablesForCamunda(){
        ProcessEngine engine         = ProcessEngines.getDefaultProcessEngine();
        RuntimeService runtimeService = engine.getRuntimeService();


        runtimeService.setVariable(Constants.KEY_WF_CRUD_API_BASE_URL,wfCrudApiBaseUrl, null);
        runtimeService.setVariable(Constants.KEY_CREATE_WORKFLOW,createWorkflowUrl, null);
return runtimeService 
}

Again I would like to set up these variables only once, as they are NOT going to changes for every bpmn file. Not sure to which class in camunda I need to setup these variables.

I would like to use these variables in process instance (in my bpmn files).
I have 20 bpmn files in my project, all these bpmn files would need these variables (URL1, URL2) and these are stateless variables, these are not going to change for across for every bpmn file.
All bpmn files are using these variables (URL1, URL2).
I would like to set these variables once and use it across different bpmn process

I tried using RuntimeService, but it did’nt work.
Any suggestion would be a great help

thanks,
Sharath

@sharath.java525 If you follow microservices pattern, then the global variables can be set by creating a microservice for spring cloud config server. In config server we can create our variables and configuration in two ways.

  1. Configurations from GIT Link reference
  2. Using local file system / Environment variables.

For local file system: db.properties , db-test.properties , db-prod.properties , db-dev.properties. Like we can create any profiles for variables and configuration.

Or in the application initialize and cache the variables using hashmap.


@Component
public class ApplicationCache {
    public static Map<K, V> map = new HashMap<>();

    @PostConstruct
    public void init() {
            map.put(key, value);
        }
} 
 

Or if you want to add those static variables to every process, then you can provide a process engine plugin which will set those variables for every process instances.

Refer this example for writing process engine plugin :

Hello aravindhrs, thanks for your reply.

Here what I was trying to achieve is
to your reply, how do I set map object to camunda RuntimeService?
I would like to set this only ONCE.
I would like to use this map object in process instance (in my bpmn files)

Also I updated my question, to make it more readable