Domanda

Is it possible (and if so: how) to add a custom Job to the jobexecutor in camunda BPM? My requirement is to execute a process-related Service by Timer or Loop. I do NOT want to model this in the BPMN directly, since it is not really part of the process. I could start additional arbitrary processes containing just one async Service task to archieve this, but I would prefer adding a method call containing the SOAP/REST/RMI call to the Job Queue Directly without the extra effort. Anyone tried this before?

È stato utile?

Soluzione

This is an advanced question. It is possible to create a Job using internal API. You need to provide two things:

A custom Job handler:

public class CustomjobHandler implements JobHandler {

  public static final String TYPE = "customjobHandler";

    public String getType() {
      return TYPE;
    }

    public void execute(String configuration, ExecutionEntity execution, CommandContext commandContext) {
      // provide custom job execution logic
    }    
}

The job handler is added to the process engine configuration. See (customJobHandlers list).

Command for creating the Job

For example from a Java Delegate (you could also use a custom command).

public class CreateJobCommand implements Command<String> {

  public String execute(CommandContext commandContext) {

    MessageEntity message = new MessageEntity();
    message.setJobHandlerType(CustomJobHandler.TYPE);
    String config = "some string you want to pass to the hanlder";
    message.setJobHandlerConfiguration(config);

    Context
      .getCommandContext()
      .getJobManager()
      .send(message);

    return message.getId();
  }

}

This creates a "Message Entity" which executes as soon as possible. If you want a timed execution you can create a TimerEntity. Then you can execute the command on the command executor of the process engine.

Edit: to test this in the Standalone Engine, you have to add the CustomJobHandler to the camunda.cfg.xml:

<property name="customJobHandlers">
 <list>
   <bean class="<FQN of CustomJobHandler>" />
 </list>
</property>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top