0

I Have a flowable workflow which I need to suspend at a certain stage, Then restart the same workflow from a JMS Listener based on a jms message.

Here I have written a delegate to suspend the process and save the processId along with another ID called PkgId.

@Slf4j
@Component
public class ValidationDelegate extends AbstractBaseUtil {

    protected Expression restEndPoint;

    @Autowired
    private ProcessInstancePkgIdMapRepository repo;

    @Override
    public void executeInternal(DelegateExecution delegateExecution) {

        RuntimeService runtimeService = CommandContextUtil.getProcessEngineConfiguration().getRuntimeService();
        runtimeService.suspendProcessInstanceById(delegateExecution.getProcessInstanceId());

        ProcessInstancePkgMap pkgMap= new ProcessInstancePkgMap ();
        pkgMap.setPkgId(1235L);
        pkgMap.setProcessInstanceId(delegateExecution.getProcessInstanceId());

        ProcessInstancePkgMap map = repo.save(pkgMap);

        log.info("saved map {}", map);
    }
}

Then on a Separate class which has a method works as a JMS Listener, listens for a Tibco topic named “test.topic”. This method receives a message from tibco topic which contains PkgId. By querying the repo with PkgId I’m able to find the relevant process instance id which was saved in the previously explained delegate. I’m trying to activate the suspended process afterwards from the process instance id

@Component
public class JMSListener {

    @Autowired
    private RuntimeService runtimeService;

    @Autowired
    private ProcessInstancePkgIdMapRepository repo;

    @JmsListener(destination = "test.topic", containerFactory = "jmsListenerContainerFactory")
    public void receiveMessage(TextMessage message) throws Exception {

        ObjectMapper objectMapper = new ObjectMapper();
        ValidationMessage validationMessage = objectMapper.readValue(message.getText(), ValidationMessage.class);

        ProcessInstancePkgIdMap idMap =
                repo.findByPkgId(validationMessage.getPkgId());

        runtimeService.activateProcessInstanceById(idMap.getProcessInstanceId());

    }
} 

But Getting an exception as, org.flowable.common.engine.api.FlowableObjectNotFoundException: Cannot find processInstance for id ‘e84d407a-c043-11ea-b877-0a0027000002’. when runtimeService.activateProcessInstanceById(idMap.getProcessInstanceId()); is called from above method.

I checked all process instances via rest. But the result was empty. What Am I missing here? Does suspending the process makes it terminate? What is the approach to restart the suspended/paused workflow.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Shenali Silva
  • 127
  • 3
  • 9

1 Answers1

0

You cannot suspend a process instance from a service task within that process instance.

What you are looking for is the triggerable Service Task explained in detail here. In a nutshell the triggerable service task is a pattern to trigger some external work, which will cause the service task to be a wait state and then you can trigger the process instance when you receive the JMS topic. Your delegate will then need to implement TriggerableActivityBehavior.

Filip
  • 19,269
  • 7
  • 51
  • 60