Collect or Aggregate messages based on counter using NWBPM step by step
We had several requirement where we needed to collect a certain number of messages using BPM. In ccBPM, we used achieve this using Loop step like below where we used to define a loop and a counter and once the counter reached to the end condition, the loop step was terminated.
So how to achieve the similar functionality using NWBPM.Below is the process view.
In my scenario, the input message looks like below.
The NWBPM is going to accept 5 message with same structure and aggregate those in a single message.
I am not going into PO ESR ID design as that is pretty simple. We are just having one ICO to pass the message with above structure to BPM and another ICO to receive the aggregated message out of BPM and write that into a file.
I will describe the properties of the steps I created in BPM.
- Data Objects:
This is a simple data object of type Integer to count the number of message received by the process.Below is the properties.
This DO is created from the data type DT_SRC which is created automatically once we imported the related Service Interface from PO.This acts as a variable/container to hold the intermediate messages within BPM process.
- Start Step: This step is to receive the first File/Message and trigger the BPM process.Here we also initialize the message counter to 1.
In the output mapping properties, we have initialized the counter to one by defining below function and mapped the first input file/message to Inbound DO which was created earlier.
- Uncontrolled Merge: This is just a dummy step to make/complete the loop as exclusive choice can not have 2 input.
- Exclusive Choice(checkCount):Here we check whther the counter reached to 5 or not. If not then the process continues with Continue line, else process diverted to CountReached line.
Condition for CountReached line as below.
- Intermediate Message(Await Next Message): If the count of number of messages is not reached to 5 then we await for next message to come in.
Here we need to use a trigger to receive the next messages.In my case I have used same trigger as the file structure of the source messages are same and coming from same service interface.
In the output mapping, we need to append the new messages to the existing message in the process.
Here also we need to set the correlation so that the next messages are correlated based on the company name on the incoming messages. So basically if the process is called by multiple instances then it will generate the aggregated output based on the same company name.
- MappingStep(IncrementCounter):In this step we just increment the counter by 1.
Double clicking on the [-] sign of the mapping line of the Counter will show you the function.
- Automated Activity(SendAggregatedMessages):Once the counter reached to 5, this step will be executed where we have just sent the aggregated output to PO.
- End: This is used to terminating the process.
That is it!!
The output should look like below.