cancel
Showing results for 
Search instead for 
Did you mean: 

how to connect to task service without REST

chakri_7
Champ in-the-making
Champ in-the-making
Hi

If I have a activiti engine running as standalone(not using any web application) in some system A with some infinite loop in spring context, and I want to get user tasks from system B and complete them, how can I achieve that?

I tried to use RMI to export task service from system A- but it seemed to resolve to null on RMI client at system B, I coudn't get why?

Since I am not deploying in any webapp, I don't think I can use REST right(NO HTTP available)?

So basically is there a way to expose task service as some service on TCP port? other than using REST?

Please provide suggestions…


Thanks
5 REPLIES 5

frederikherema1
Star Contributor
Star Contributor
There is no default way of doing this in Activiti? However, If you use spring-remoting, you can expose any interface you want over TCP. Also, we use restlet for REST-implementation, which is also capable of creating a standalone HTTP-server, without the need for a container/servlet-environment…

CODE AT SYSTEM A:
<bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
  <property name="dataSource" ref="dataSource" />
  <property name="transactionManager" ref="txManager" />
  <property name="databaseSchemaUpdate" value="true" />
  <property name="jobExecutorActivate" value="true" /> <!– FOR TIMERS/CRON –>
  <property name="deploymentResources" value="classpath*Smiley Tonguerocessflows/testprocess_flow.bpmn20.xml" />
</bean>

<bean id="runtimeService" factory-bean="processEngine" factory-method="getRuntimeService" />
<bean id="taskService" factory-bean="processEngine" factory-method="getTaskService" />
<bean id="historyService" factory-bean="processEngine" factory-method="getHistoryService" />
<bean id="managementService" factory-bean="processEngine" factory-method="getManagementService" />

<!– REMOTING –>
<bean class="org.springframework.remoting.rmi.RmiServiceExporter">
        <property name="serviceName" value="task-service"/>
        <property name="service" ref="taskService"/>
        <property name="serviceInterface" value="org.activiti.engine.TaskService"/>
        <property name="registryPort" value="1234"/>
    </bean>

And at System B(CLIENT):

<bean id="taskServiceClient" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
        <property name="serviceUrl" value="rmi://localhost:1234/task-service"/>
        <property name="serviceInterface" value="org.activiti.engine.TaskService"/>
    </bean>

and trying to use as:

           TaskService taskService = (TaskService) context.getBean("taskServiceClient");
 
  List<Task> tasks = taskService.createTaskQuery().taskAssignee("user1").list();
 
  for (Task task : tasks) {
   System.out.println(task.getProcessVariables());
   taskService.complete(task.getId());
  }

It is raising exception on SYSTEM B as:

Exception in thread "main" java.lang.NullPointerException
at org.activiti.engine.impl.TaskQueryImpl.ensureVariablesInitialized(TaskQueryImpl.java:427)
at org.activiti.engine.impl.TaskQueryImpl.executeList(TaskQueryImpl.java:482)
at org.activiti.engine.impl.AbstractQuery.list(AbstractQuery.java:115)
at com.process.flow.client.TaskClient.main(TaskClient.java:19)

Please provide any suggestions…




frederikherema1
Star Contributor
Star Contributor
The task-queries should be executed on machine A, those aren't transferrable over removing. The results of the queries are… I suggest writing an additional service yourself that uses the taskService's queries. Expose this service remote.

chakri_7
Champ in-the-making
Champ in-the-making
Hi

That worked!!!

Thanks

frederikherema1
Star Contributor
Star Contributor
Glad it worked!