logo

Using the ‘Send Message’ and ‘Receive Message’ activities

Consider a use case of these activities. The process author assigns multiple tasks by using the subprocess activity and tracks task execution with messages. The number of tasks is not determined beforehand; the author specifies the variable of the block type, each string in the block starts a respective subprocess. Once the subprocess is complete, the message is sent to the parent process with the processing results.

Map of the parent process:

To assign multiple tasks simultaneously, use an External Sub-Process activity with the Multiple execution marker. This activity sends to the subprocess the string variable which stores a description of the task made by the author (the string is taken from the block by a script) and a link to the parent process (will be used to send a message).

Map subprocess:

As a result, an executor receives a task description. Once the task is completed, the executor leaves a respective comment. Further, comments will be transmitted to the parent process with the massage, and the task author will be able to read it.

Consider how it is implemented. Let's start with the parent process. It is implemented as two cycles: a starting cycle and a receiving cycle.

A starting cycle is about starting subprocesses. Once the block is filled out, the script is used to prepare the data for the starting cycle: it counts the number of strings in the block, reset counter, specifies the expected number of messages:

context.Counter = 0;
context.MessageCounter= 0;
context.TotalStrings= context.Blok.Count;
context.ExpectedNumberofMessages = context.Blok.Count;

After that, a system runs a script to determine the number of the string in the block, which will be transmitted to the new process. At the same time, the script counts the number of the started instances and determines the status of each transmitted string:

context.String ="";
context.Counter +=1;
foreach (var item in context.Blok) {
if ((item.Status=="Not processed")&&(context.String=="")){
item.Status = "Send for processing";
context.String = item.Parameter;}}

Once these scripts are completed, the sub-processes must be executed. Setting up the "Send Message" activity:

When configuring the "Send Message" and "Receive Message" activities, it is necessary to specify the "Message Type", which will be transmitted between processes. The Type settings include two properties: the type name and the type parameters. The name determines which message will be sent (received); the type parameters are the body of the message and the properties to be transmitted.

In order to send the message to the correct process instance, specify the "Parent instance" variable in the activity. The value of this variable is written as result of the "Sub-Process" activity. Send back the "Tasks Description" variable to write a comment and mark the appropriate block string (it serves as a string identifier).

The "Receive Message" settings window. If you specify a script, a setting window will look similar.

The first script ("A condition for processing") is triggered when a message is received. The second script will be performed depending on the output of the first script. The "Processing message" script is performed, if the first script returns ‘True’ or does not return anything. In this example, the script writes the received comments in a block of tasks, updates the status of the string and counts the received messages:

foreach (var item in context.Blok) {
if (context.Stroka == item.Parameter)
item.Status="Processed";  }
context.MessageCounter = context.MessageCounter +1;

Once the required number of messages is received, the author is assigned a task to check the results of the tasks.