5 Replies Latest reply on Jul 4, 2013 5:03 AM by synclpz

    jBPM noob questions

    synclpz Novice

      Hello, all. I got some noob (maybe) questions concerning implementing existing scenarios in jBPM. I got some proprietary workflow manager runtime (running on AS7) and tooling to define workflows via graphical editor. The workflows are rather simple and consist of nodes (with in/out parameters) and arrows pointing to the next node (or nodes if current node makes some decisions). Every node is a simple java class that allows to perform some operation: math operations, database lookups/stores, invoke HTTP GET's, log, start another workflows, some proprietary actions and so on.

       

      Now I want to migrate existing service logic to jBPM (actually may be to SwitchYard with jBPM as process orchestrator). Beacause of almost no knowledge in "perfect" BPMN I'm afraid of making wrong architectural decisions

      I would be very glad if someone could propose me the right solutions or just post some links to the right places to read!

       

      My simple process looks like this:

       

      1. Log some input vars

      2. Prepare (map) some additional parameters

      3. Query some application properties (config)

      4. Query DB with request based on prepared data

      5. Modify data (e.g. update modification time)

      6. Update data in DB

      7. Invoke some sub-process

      8. Execute some action through, for example, HTTP or other (proprietary) interface

      9. If everything ok, commit data in DB, else rollback and write log

      10. Map some paramerers for output

      11. Finish

       

       

      I cannot understand clearly how this should be implemented using jBPM tools. As I could imagine, logging and parameter mapping and runtime bean fileds updating could be performed via Script Node with java expressions, but may be I should use some other tools for it? I cannot find how do I query DB, update DB: is it only done through custom Service Node? Is there a possibility (examples) to use ORM for domain-specific data model? How could I invoke sub-process with, for example, process name and parameters derived in run-time? If someone could supply any more or less complex examples of jBPM usage: with custom data model or custom services invocations, it would be very appreciated.

        • 1. Re: jBPM noob questions
          Mauricio Salatino Master

          Hi Viktor,

          As you mention in your question, you will need to use Custom Service Node types for doing interactions. Try to avoid using script nodes. Custom Service Nodes are implemented creating new implementations of the WorkItemHandler interface. Those implementations will interact with your external systems. If those interactions are Syncrhonous, jBPM will behave in the same way that your old framework does.

          Regarding the operations with the DB which seems to be transactional, it depends on how do you want to do it. If you start a transaction against your DB inside a workItemHandler and then write the logic to see if everything else went right and commit that transaction, everythhing should work. Notice that for what you describe, you don't need to persist your "Flows" because all what you need is to execute the steps and commit or rollback the information to another external database.

           

          Cheers

          • 2. Re: jBPM noob questions
            synclpz Novice

            Mauricio, thanks for the answer. By the way your blog was also very helpful %)

             

            Everything's clear about interactions.

            Try to avoid using script nodes.

             

            Is it ok to use Script Nodes to make thing like "user = String.valueOf(userBean.Name) + "-" + String.valueOf(userBean.Id);"?

             

             

            Regarding the operations with the DB which seems to be transactional, it depends on how do you want to do it. If you start a transaction against your DB inside a workItemHandler and then write the logic to see if everything else went right and commit that transaction, everythhing should work.

            Could you clarify some things about DB: I found "Data Object" elements in eclipse designer palette, is it something concerning data access? Or what are they made for? It confuses me a little.

             

             

            Notice that for what you describe, you don't need to persist your "Flows" because all what you need is to execute the steps and commit or rollback the information to another external database.

            Also, concerning persistence and clustering: if I persist my flow instance, does it provide the ability to restart flow from the point it was persisted after system crash/shutdown and restoration to operational state? Could it be configured (coded?) to failover process instances to other running system restoring states from persistent store?

            • 3. Re: jBPM noob questions
              synclpz Novice

              Mauricio, please help me with another question, concerning transactions: if I start UserTransaction in one service task is it propagated to another service task in the same (or sub) flow?

              • 4. Re: jBPM noob questions
                Mauricio Salatino Master

                Hi Viktor,

                About your questions:

                1) I always discourage the use of script nodes because you are basically writing java inside an xml file, which will make your life more difficult when you do refactorings, it doesn't provide any syntax checking, etc, etc. But if the code that you want to put there is simple enough and it will not cause you troubles in the future you can go ahead knowing the risks.

                 

                2) Data Objects are defined in the BPMN2 specification and helps  you to define from where your data is comming from, I usually mention Data Objects as quite advanced structures. As far as I know they are supported in jBPM but I would prefer to work with process variables directly. From the technical point of view it's easier at least. If you take a look at the BPMN2 specification you will see that Data Objects are exactly the same as Process Variable, but the later doesn't have a graphical representation in the process diagram.

                 

                3) About persistence, if you are planning to use persistence you will need to demarcate your transactions. This is not difficult, because it just means that you will need to decide which Activities inside your process will be asynchrnous (will end the current transaction) and which will be sync (will be executed inside the current transaction) . If you have all the Activities in your process as Sync activities the process state will not be persisted between each of them.

                 

                4) About user transactions.. This is a complicated topic to explain in a couple of sentences, but I will try to make it short. jBPM will handle internally the transaction for the resources that are configured within jBPM. If you have your own external databases and if you are configuring your own databases outside jbpm you will be in charge of handling transactions. So how the transactions are propagated its completely up to you. In the other hand, if you configure your databases as transactional resources within jbpm, jbpm will define when to start and end the transactions based on the safe points of the processes (Sync and Async activities) .

                 

                I hope this helps!

                 

                Cheers

                • 5. Re: jBPM noob questions
                  synclpz Novice

                  1-2-3 got it, thanx a lot.

                   

                  4) Yes, I've also experienced much joy and pain with transactions, up to writing my own XA transaction manager for very specific use %)

                  What do you mean saying

                   

                   

                  In the other hand, if you configure your databases as transactional resources within jbpm, jbpm will define when to start and end the transactions based on the safe points of the processes (Sync and Async activities) .

                  What do I do to use database inside jBPM? Is it just for process data persistence or I could use some datasources to obtain and set domain specific data?