Once we have a BPM system component to centralize our process engine, we will need a standard way to access that environment. It is important to expose such environments in order to not clutter other systems with complicated or dependency loaded APIs.
We've seen how to add a web service component to expose the KIE Workbench's internal components through a SOAP-based web service, but there are more standard ways of accessing our environment, which are preconfigured in the KIE Workbench. Those mechanisms also come with client components, based on the RuntimeEngine
interface, for which implementations are provided to access the internal runtime engines of the KIE Workbench through the following two protocols:
Queues
The following diagram shows how these different ways of connecting external systems to the KIE Workbench are implemented:
As the preceding diagram shows, the RemoteRuntimeEngine
object takes advantage of the command pattern-based KIE session and task service to expose the exact same API by implementing a remote way to execute the commands. Using the RemoteCommandExecutor
object, it can send XML serializations of each command through different protocols, and as long as a server is prepared to receive them, interaction between the client and server could be done through the same API you would use to run the process engine locally.
In order to use these remote APIs, you need to add the kie-services-client
dependency to your projects, as follows:
<dependency> <groupId>org.kie.remote</groupId> <artifactId>kie-services-client</artifactId> <version>6.1.0.Beta3</version> </dependency>
We will go into detail on how to use each one of these remote invocation strategies in the following sections.
The simplest way to communicate with the KIE Workbench is through the REST interface. A group of REST service classes expose a series of URLs to access different runtime engines inside the KIE Workbench. The following table shows some of the URLs:
URL |
Functionality |
---|---|
|
This URL allows you to start a process instance. Here, the parameters are passed through the body. |
|
This URL allows you to send the abort signal to a running process instance. |
|
This URL allows you to send a specific signal to a running process instance. |
|
This URL sends a signal to the whole KIE session instead of just one process instance. |
|
This URL allows the user to complete a work item remotely. Here, the parameters are sent through the body. |
|
This URL allows the user to abort a work item remotely. |
|
This URL allows the user to execute a command sent through the post body. |
|
This URL retrieves the value of a variable for a specific process instance. |
|
This URL retrieves a specific process instance. |
|
This URL allows you to perform multiple different operations on top of the task service (claim, activate, complete, and so on). Here, the parameters are sent through the post body. |
|
This URL allows you to perform queries on top of the task service database. |
|
This URL retrieves the contents of a task (its task inputs, outputs, and errors). |
|
This URL retrieves a specific content of one specific task. |
|
This URL clears the audit information of the task database. |
|
This URL clears the audit information of the process database. |
|
This URL retrieves historical information of all completed and running process instances. |
|
This URL retrieves all historical info about one specific process instance. |
|
This URL retrieves all historical info about nodes of one specific process instance. |
|
This URL retrieves all historical info about variables of one specific process instance. |
|
This URL show all the deployments that are available. |
|
This URL updates a deployment. |
|
This URL removes a deployment. |
|
This URL shows all the deployments that are available. |
The most important URL exposed is probably the "execute" URL: /rest/runtime/{deployment-id}/execute
. Through this URL, using the command pattern, every single function in the KIE session and the task service can be implemented using the same API. This is the one used by the implementation at the kie-services-client
dependency to expose the RemoteRuntimeEngine
class. The following code snippet shows how to build a REST remote runtime engine:
RuntimeEngine engine = RemoteRestRuntimeEngineFactoryBuilderImpl. newBuilder().addUrl(new URL("http://localhost:8080/kie-wb")). addDeploymentId("org.jbpm:HR:1.0").addUserName("mariano"). addPassword("mypass").build().newRuntimeEngine();
You can see that we are passing four elements to the RemoteRestRuntimeEngineFactoryBuidlerImpl
class: a URL for the KIE Workbench, a release ID for identifying a runtime manager, and a username and a password to log in to the application and pass credentials to what I will do on top of the created RuntimeEngine
.
Once the RuntimeEngine
object is created, we can use it as any other RuntimeEngine
we built in our local environment. Internally, it will create commands for every method invoked in the KIE session and task service, serialize them into XML, and send them through the execute URL.
You can find an example in the remote-invocations
project, in the SignalEventAppREST
class. You can run it directly from the remote-invocations
path by typing the following command:
mvn -Prest
Another way of accessing the KIE Workbench runtime engines is through the JMS implementations. It uses a set of queues to send serialized versions of the command objects for task service and KIE session method executions. These commands, whether they are sent to the task service or the KIE session, are sent through two different queues: jms/queue/KIE.TASK
or jms/queue/KIE.SESSION
queues, respectively. Responses are handled through the jms/queue/KIE.RESPONSE
queue.
These are the default configurations in the KIE Workbench application, but they can be changed in the bpms-jms.xml
file under the WEB-INF/
folder of the KIE Workbench.
There is another queue we haven't mentioned because, for the moment, it is not managed by the RemoteRuntimeEngine
interface. This queue is the audit queue. It manages requests for the AuditLogService
interface, to access the history logs from outside applications.
In order to create code that could manage messages for the first three queues in a standard way, we must create the runtime engine through the provided API, as shown in the following code snippet:
InitialContext ctx = new InitialContext(); QueueConnectionFactory connFactory = (QueueConnectionFactory) ctx.lookup("jms/RemoteConnectionFactory"); Connection conn = connFactory.createConnection( "mariano", "mypass"); Session session = conn.createSession(true, Session.AUTO_ACKNOWLEDGE); Queue ksQueue = (Queue) ctx.lookup("jms/queue/KIE.SESSION"); Queue taskQueue = (Queue) ctx.lookup("jms/queue/KIE.TASK"); Queue respQueue = (Queue) ctx.lookup("jms/queue/KIE.RESPONSE"); RuntimeEngine engine = RemoteJmsRuntimeEngineFactoryBuilderImpl. newBuilder().addDeploymentId("org.jbpm:HR:1.0"). addConnectionFactory(connFactory).addKieSessionQueue(ksQueue). addTaskServiceQueue(taskQueue).addResponseQueue(respQueue). addUserName("mariano").addPassword("mypass"). build().newRuntimeEngine();
The preceding code snippet does a lot more configuration, mainly to access all the JMS components needed. We first need to connect to an initial context to gain access to our JMS ConnectionFactory
and Queues
, and then we pass those to the factory along with a release ID, a username, and a password.
There is an example provided in the SignalEventAppJMS
class of the remote-invocations
project. You can run it directly from the remote-invocations
path by typing the following command:
mvn –Pjms
Due to default permission configurations in JBoss Application Server 7.1, you need to have the guest
role added to the user with which you log in to the KIE Workbench. You can do so by editing the application-roles.properties
file under standalone/configuration
, changing mariano=admin
to mariano=admin,guest
.
Also, if you want to run the remote-invocations demo, you will also need to add the mariano
user, with password mypass
, to the application realm using the add-user.sh
or add-user.bat
script of the JBoss Application Server.