Uploaded image for project: 'jBPM'
  1. jBPM
  2. JBPM-3512

Allow developer-defined correlationId in addition to processInstanceId

    Details

      Description

      Currently a processInstanceId is the only way an application can identify a process instance to a ProcessRuntime. However, many existing applications and APIs already have the notion of a correlationId which can be used to uniquely identify a unit of work. This work could be much larger than just the BPM process, and thus encompass it. In those situations, being able to identify a process instance using a developer-defined correlationId (which identifies the larger work) would be beneficial. The obvious workaround is for applications to maintain their own table mapping correlationId to processInstanceId, however this would be a nice feature for jBPM to provide out-of-the-box.

        Gliffy Diagrams

          Issue Links

            Activity

            Hide
            dward David Ward added a comment - - edited

            Implementing something like JBPM-2505 could resolve this issue.

            Show
            dward David Ward added a comment - - edited Implementing something like JBPM-2505 could resolve this issue.
            Hide
            dward David Ward added a comment -

            SWITCHYARD-325 depends on this issue.

            Show
            dward David Ward added a comment - SWITCHYARD-325 depends on this issue.
            Hide
            dward David Ward added a comment -

            Meciej, I see you are the new owner of this issue. Is there an ETA for getting this issue resolved? Thanks!

            Show
            dward David Ward added a comment - Meciej, I see you are the new owner of this issue. Is there an ETA for getting this issue resolved? Thanks!
            Hide
            swiderski.maciej Maciej Swiderski added a comment -

            David, I should have something in like few days. Need to test it quite a lot as it goes through several components (common: kie-api, drools and jbpm). Just to give you some heads up on what it will include:

            • expose methods on StatefulKnowledgeSession to:
            • start process with custom business key - must be unique,
            • get process instance by business key,
            • create (and not yet start) process instance with business key
            • business key will be additional table column so it can be queried directly if needed - as opposed to being included in the byte array
            • enhance BAM logger so the business key is stored there as well

            let me know if there is anything else that would be required for this issue

            Show
            swiderski.maciej Maciej Swiderski added a comment - David, I should have something in like few days. Need to test it quite a lot as it goes through several components (common: kie-api, drools and jbpm). Just to give you some heads up on what it will include: expose methods on StatefulKnowledgeSession to: start process with custom business key - must be unique, get process instance by business key, create (and not yet start) process instance with business key business key will be additional table column so it can be queried directly if needed - as opposed to being included in the byte array enhance BAM logger so the business key is stored there as well let me know if there is anything else that would be required for this issue
            Hide
            dward David Ward added a comment -

            Meciej, this is awesome. Thanks so much!

            Show
            dward David Ward added a comment - Meciej, this is awesome. Thanks so much!
            Hide
            swiderski.maciej Maciej Swiderski added a comment -

            David, I'll start working in this again as after some discussion need to change the implementation slightly to be prepared for extensions. Will update jira as soon as will have it ready.

            Show
            swiderski.maciej Maciej Swiderski added a comment - David, I'll start working in this again as after some discussion need to change the implementation slightly to be prepared for extensions. Will update jira as soon as will have it ready.
            Hide
            dward David Ward added a comment -

            Thanks again. Much appreciated!

            Show
            dward David Ward added a comment - Thanks again. Much appreciated!
            Hide
            swiderski.maciej Maciej Swiderski added a comment -

            Resolved for 6.0, here comes a simple code snippet that illustrates the usage:
            CorrelationKeyFactory factory = KieInternalServices.Factory.get().newCorrelationKeyFactory();
            ...
            // create your kbase
            // create your ksession

            CorrelationKey key = factory.newCorrelationKey("mybusinesskey");

            // start process instance
            ProcessInstance processInstance = ((CorrelationAwareProcessRuntime)ksession).
            startProcess("com.sample.bpmn.hello", getCorrelationKey(), null);

            // next the process instance can be found be correlation key:

            ProcessInstance processInstanceCopy = ((CorrelationAwareProcessRuntime)ksession).getProcessInstance(key);

            Since CorrelationKey support is introduced to internal API it requires additional cast to get access to correlation based methods.

            The above example code shows single valued CorrelationKey but multi valued correlation keys are supported as well. To create multi valued correlation key:

            List<String> properties = new ArrayList<String>();
            properties.add("customerid");
            properties.add("orderid");
            CorrelationKey multiValuedKey factory.newCorrelationKey(properties);

            then such key can be used exactly same way as single valued key is used.

            CorrelationFactory is responsible for providing the right instances of CorrelationKey and shall be always used to build CorrelationKey objects.

            CorrelationKey does not have to be stored to be able to use it later on, e.g. to retrieve process instance meaning can be recreated whenever it is needed. Lookup is based on values. In case of multi valued keys best is to keep same order of properties every time correlation key is recreated.

            Show
            swiderski.maciej Maciej Swiderski added a comment - Resolved for 6.0, here comes a simple code snippet that illustrates the usage: CorrelationKeyFactory factory = KieInternalServices.Factory.get().newCorrelationKeyFactory(); ... // create your kbase // create your ksession CorrelationKey key = factory.newCorrelationKey("mybusinesskey"); // start process instance ProcessInstance processInstance = ((CorrelationAwareProcessRuntime)ksession). startProcess("com.sample.bpmn.hello", getCorrelationKey(), null); // next the process instance can be found be correlation key: ProcessInstance processInstanceCopy = ((CorrelationAwareProcessRuntime)ksession).getProcessInstance(key); Since CorrelationKey support is introduced to internal API it requires additional cast to get access to correlation based methods. The above example code shows single valued CorrelationKey but multi valued correlation keys are supported as well. To create multi valued correlation key: List<String> properties = new ArrayList<String>(); properties.add("customerid"); properties.add("orderid"); CorrelationKey multiValuedKey factory.newCorrelationKey(properties); then such key can be used exactly same way as single valued key is used. CorrelationFactory is responsible for providing the right instances of CorrelationKey and shall be always used to build CorrelationKey objects. CorrelationKey does not have to be stored to be able to use it later on, e.g. to retrieve process instance meaning can be recreated whenever it is needed. Lookup is based on values. In case of multi valued keys best is to keep same order of properties every time correlation key is recreated.
            Hide
            dward David Ward added a comment -

            Great work. Thanks!

            Show
            dward David Ward added a comment - Great work. Thanks!

              People

              • Assignee:
                swiderski.maciej Maciej Swiderski
                Reporter:
                dward David Ward
              • Votes:
                2 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Development