Injecting preprocessing logic to a job worker

I need to run some pre-processing logic before some job worker of a service task is run. In my pre-processing logic, I need to obtain secret information and pass it to the job worker. This is secret information, so it must not be visible in operate. I was thinking of using custom headers since I cannot use variable.

I tried execution listener on the service task. Seems like I couldn’t set the custom headers here. Is there anyway to pass these secret information to the service task’s job worker?

Hi @khew.

Please refer here for possible ways to use secrets:

And also you could directly inject your secrets into your job workers inside your application (e.g. autowiring via spring boot or getting them from a vault). If your job workers don’t save those secrets as variables, they won’t be visible in operate.

You cannot use service task headers for that. They are meta-data and belong to the process model, not to the process instance (Service tasks | Camunda 8 Docs).

I think you should implement this behaviour directly in your worker by implementing it in a base class like in this simple example or similar (using simply classic OO in java):

import io.camunda.zeebe.client.api.worker.JobHandler;

public abstract class BaseWorker implements JobHandler {

    protected String secretInformation;

    public BaseWorker() {
        this.secretInformation = "secretInformation";
    }
}

and in your worker:

import io.camunda.zeebe.client.api.response.ActivatedJob;
import io.camunda.zeebe.client.api.worker.JobClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ServiceWorker extends BaseWorker {

    private static final Logger logger = LoggerFactory.getLogger(ServiceWorker.class);

    @Override
    public void handle(JobClient client, ActivatedJob job) {
        logger.debug(secretInformation);
    }
}
1 Like