<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">

<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>

                                <td>

                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="https://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>

                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px;  -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
    Design pattern for routing to multiple jBPM processes?
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="https://community.jboss.org/people/jamesbeam">Jim B</a> in <i>jBPM</i> - <a href="https://community.jboss.org/message/804680#804680">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>I am using jBPM 5.4 with persistence.&#160; I am still a jBPM noob, so thanks in advance for your patience getting through this explanation...</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I have a ksession that will be running multiple long-running processes.&#160; These process flows are the same - only the variables in the processes are different.&#160; </p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>The basic use case it that I have events coming into a "router" that based upon message content will be passed to an existing process instance (if the related process exists).&#160; If a process instance does not yet exist for that event, a new one is created.&#160; </p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I would greatly appreciate any thoughts on design patterns to implement this (managing processes in the kession and routing events to them).</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Relating to design, I have considered; </p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>1) Create a single-node process with a "routing" WorkItemHandler node.&#160; This instance will receive the event and perform all of the checking/routing/process instantiation logic.&#160; Basically, iterate through each process in the kession for the </p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>2) Create business rules that checks for (and creates) objects in the ksession representing each process that is running.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160; Pseudo code for rules would be something like:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160; rule "Send to existing process"</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; when</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; $newEventBean : NewEventBean()</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; $myProcessBean : MyProcessBean(subject matches $newEventBean.subject)</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; then </p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;signal&#160; $myProcessBean.processId&#160; with $newEventBean&gt;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160; rule "Create if process doesn't exist"</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; when</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; $newEventBean : NewEventBean()</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; not($myProcessBean : MyProcessBean(subject matches $newEventBean.subject))</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; then </p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; $newProcessBean: NewProcessBean();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; $newProcessBean.subject = $newEventBean.subject;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; $newProcessBean.instantiate(thisKsession);&#160;&#160;&#160;&#160;&#160;&#160; &lt;&lt;---inserts new process instance into ksession</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; insert($newProcessBean);</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160; (and when a process ends, it would need to retract the related newProcessBean)</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I am more familiar with java development than drools rule-jbpm integration, so I am leaning towards option 1.&#160; (Specifically, for example, I'm not sure how to create a process from a rule or how to signal one, so I'd more likely to implement methods like NewProcessBean.instantiate() in a java method in my newProcessBean anyway <span> :) </span>)</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Any thoughts about option 1 or 2?&#160; Am I missing a more obvious/better solution?</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>(Possibly something like sending a signal to a ksession where the correct process catches it and acknowledges it in some way - so that if an acknowledgement isn't received a new process is created.&#160; Can a process be configured to ALWAYS catch a signal AFTER another process, so that my "final" process could act like an "otherwise" statement and would just instantiate a new process?)</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Thank you again for any thoughts,</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>-J</p></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Reply to this message by <a href="https://community.jboss.org/message/804680#804680">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in jBPM at <a href="https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


                </td>
            </tr>
        </tbody>
    </table>

</div>

</body>
</html>