4 Replies Latest reply on Aug 4, 2014 3:27 AM by Maciej Swiderski

    Start jBPM process via rest API asynchronously

    Laura delli Paoli Master

      Hello everybody,

      I'm starting jBPM processes via REST API (jbpmConsoleUrl + "/rest/runtime/" + deploymentId + "/withvars/process/" + processDefId + "/start" + "?" + encodedParameters) using my own client.

      It seems that my client waits until jBPM precess completes, this behaviuor is not ok for long running processes since it keeps alive connection for a long time.

       

      Is there any API for launching processes asynchronously?

       

      Thanks

       

      Laura

        • 1. Re: Start jBPM process via rest API asynchronously
          Mauricio Salatino Master

          One way to solve it for now could be to add the first task in your process async, that will cause that the start process and the scheduling of the first task will be done sync but as soon as the first task is scheduled your client will gain control again.

           

          We are planning to expose the executor API via rest so you can just call the StartProcessCommand which will be executed asynchronously by the executor component in future version.

          Regards

          1 of 1 people found this helpful
          • 2. Re: Start jBPM process via rest API asynchronously
            Laura delli Paoli Master

            Thanks for your answer, Mauricio!

             

            What do you mean with "add the first task in your process async,"? Should I add a task named asynch or simply a task whose handler doesn't call workItem.complete() method?

             

            Laura

            • 3. Re: Start jBPM process via rest API asynchronously
              Laura delli Paoli Master

              Hi,

              I tansformed my first tasks (thah only write a log message) into an asynchronous one:

              public class AsyncLogTaskHandler extends SaakAkTaskHandlerAbstract {

               

               

                private static Logger trace = Logger.getLogger(AsyncLogTaskHandler.class);

               

               

                @Override

                public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {

               

                final long pid = workItem.getProcessInstanceId();

                final long wiId = workItem.getId();

                trace.info("Running AsyncLogTaskHandler for work item " + wiId + " for process " + pid);

               

               

                new AsyncLogTaskExecutor(workItem, manager).run();

                }

              }

               

              with AsyncLogTaskExecutor thad does stuffs and completes the workItem, but my rest client doesn't gain control until the last task of my process completes.

               

              Mauricio said that "first task will be done sync but as soon as the first task is scheduled your client will gain control again.", did I miss something?

               

              Laura

              • 4. Re: Start jBPM process via rest API asynchronously
                Maciej Swiderski Master

                simplest way would be to use jbpm executor and its async work item handler to perform task in back ground and by that release current thread

                 

                HTH

                1 of 1 people found this helpful