Using event strategy in Pega 7 Platform real-time event processing (7.1.9)
Event strategy is a visual representation of processing logic that is applied to all events coming from a data source. Event strategies can be used to specify patterns of events, query them across a data stream, and react to the emerging patterns.
The event strategy that you create in this tutorial identifies telecommunications company customers who have more than two dropped calls within a week. When such an event pattern occurs in the telecommunications network, a new case is called for each affected customer.
- Requirements
- Creating a stream data set
- Creating an event strategy
- Referencing an event strategy from a data flow
- Configuring a static data set in a data flow
- Referencing a case from a data flow
- Creating a real-time run of a data flow
Requirements
Before starting this tutorial, build a simple Pega application on the PegaDM app (for details, see Creating an enterprise application). In your application, create the following resources:
A data flow called Call Detail Record to handle transactions that occur in the telecommunications network. Create the data flow in the <organization_name>-<app_name>-Stream class. For details, see Data Flow rule.
- A stream data set called CDR Stream and a Database Table data set called Customers Info. The CDR Stream data set processes a continuous stream of call detail records. The Customers Info data set should contain properties such as customer name and contact information. You supply this data by using an additional data set because these properties are not typically in the stream of call detail records. Create the data sets in the <organization_name>-<app_name>-Data class. For details, see Data Set rule.
A case called Contact Customer. It starts for all customers who have two or more dropped calls within a week. For details, see Adding a top-level case type.
Creating a stream data set
The stream data set that you create processes a continuous stream of call detail records coming from a telecommunications network.
- In the Application Explorer, right-click the <organization_name>-<app_name>-Data class and click > > .
Define the record configuration of the data set:
- In the Label field, enter CDR Stream.
- In the Type field, select .
- Ensure that the Apply to field contains the class where you want to save the data stream (<organization_name>-<app_name>-Data).
- Click .
- In the Stream tab of the newly created data set, you can view the services that can be used to populate the data set outside of the Pega 7 Platform.
- Click .
After you create the required resources, you can create an event strategy.
Creating an event strategy
The event strategy that you create and reference from the Call Detail Record data flow is shown in the following figure:
In this figure, the event strategy filters dropped calls for each customer and creates a one-week time window to hold the dropped calls. Next, it counts the dropped calls from the one-week window for each customer. Finally, when the number of dropped calls for a particular customer is higher than two, the Call Detail Record data flow triggers the Contact Customers case.
- In the Application Explorer, right-click the <organization_name>-<app_name>-Stream class and click > > .
Define the record configuration of the event strategy:
- In the Label field, enter DroppedCallsDetection.
- Ensure that the Apply to field contains the class where you want to save the event strategy (<organization_name>-<app_name>-Stream).
- Click .
A new instance of Event Strategy opens.
Double-click the Real-time data shape. The Real-Time Data Properties dialog box opens.
- In the Name field, enter Call Detail Record.
- In the Event timestamp section, select the System time check box.
- Click .
Navigate to theAdd icon on the right, and then select .
shape, click the- Double-click the Filter shape. The Filter Properties dialog box opens.
Specify a property from the CDR Stream, which is used to identify whether a call was dropped. In this tutorial, this is a TrueFalse property. When it is set to true for a particular call detail record, it means that the call was dropped.
- In the Name field, enter Dropped Calls.
- Click .
In the field on the left, specify a CDR Stream property to be used by the filter.
- From the drop-down menu, select the equal sign (=).
- In the right field, enter true.
- Click .
Navigate to the Real-time data shape and click the bottom Add icon to add a Static Data shape.
Double-click the Static Data shape. The Static Data Properties dialog box opens.
Specify the properties that you want to associate with the properties in the CDR Stream. The properties that you specify come from the Customers Info data set that you created; this data includes customer name and contact information.
- Click .
- Provide the name of a property.
- Repeat the step for the next property.
- When you finish, click .
- Navigate to the shape, click the Add icon, and select .
Double-click the Window shape. The Window Properties dialog box opens.
Configure a time window to hold the dropped calls coming from the CDR Stream. This sliding window contains the events for one week. When this window gradually moves with the passing of time, the events that are older than one week are removed from the window.
- In the Name field, enter One Week.
- In the Window section, select the Sliding check box.
- From the drop-down menu, select .
- In the Look for last field, enter 1.
- Click .
- Navigate to the Window shape, click the Add icon, and select .
- Double-click the Aggregate shape. The Aggregate Properties dialog box opens.
- In the Name field, enter Count of Dropped Calls.
- Click .
- From the drop-down menu, select .
- In the Aggregate field, name the property that should contain the result of your aggregation function, for example, DroppedCallsNumber.
- Click .
- Navigate to the Aggregate shape, click the Add icon, and select .
- Double-click the Filter shape. The Filter Properties dialog box opens.
- In the Name field, enter Over 2 Dropped Calls.
- Click .
- In the left field, enter DroppedCallsNumber.
- From the drop-down menu, select the greater than sign (>).
- In the right field, enter 2.
- Click .
- Double-click the Emit shape. The Emit Properties dialog box opens.
- In the Name field, enter Open Case.
- From the Emit event drop-down menu, select .
- Click .
You have just created and configured an event strategy instance called DroppedCallsDetection. Now, you need to reference it from the Call Detail Record data flow that you created at the beginning of this tutorial.
Referencing an event strategy from a data flow
Event strategies are used in data flows through the Event Strategy pattern. In this task, you reference the CDR Stream from the Source pattern in the Call Detail Record data flow and the DroppedCallsDetection event strategy from the Event Strategy pattern.
- Open the Call Detail Record data flow and double-click the Source pattern.
- From the Source drop-down menu, select .
- In the Data set field, enter CustomersInfo.
- Click .
- Navigate to the Source pattern.
- Click the Add icon and select .
- Double-click the Event Strategy pattern. The Event strategy properties dialog box opens.
- In the Results in field, specify the class that contains the event strategy (<organization_name>-<app_name>-Stream).
- In the Event strategy field, enter DroppedCallsDetection.
Add mapping between the properties from the DroppedCallsDetection event strategy and the Call Detail Record data flow.
First, you need to map the class key of the class containing the data flow with the class key of the Result in class of the event strategy. Next, you map the properties from the class that contains the data flow with the Result in class of the event strategy.
- Click .
- In the Target column, select the class key of the class that contains the Call Detail Record data flow.
In the Source column, select the class key of the class that contains the DroppedCallsDetection event strategy.
Map other properties in the same way.
- When you finish adding mapping, click .
When you finish this task, the Call Detail Record data flow should look like this example:
Configuring a Database Table data set in a data flow
Because you are using the Customer Info Database Table data set to provide additional properties that are not typically in the stream of call detail records, you need to configure the data set in the Call Detail Record data flow.
Double-click the Customers Info data set shape.
- In the Class field, specify the class that contains the Customers Info data set (<organization_name>-<app_name>-Data).
- In the Data set field, enter CustomersInfo.
Add mapping between the properties from the DroppedCallsDetection event strategy and the Customers Info data set.
First, map the class key of the class that contains the event strategy to the class key of the class containing the data set. Next, map the static properties from the event strategy to the properties from the class that contains the data set.
In the Source column, select the class key of the class that contains the Customers Info data set (<organization_name>-<app_name>-Data).
- Click .
- In the Target column, select a property from the class that contains the DroppedCallsDetection event strategy.
In the Source column, select a property from the class that contains the Customers Info data set.
Map the other properties in the same way.
When you finish adding mapping, click
.
- Click .
When you finish this task, the Call Detail Record data flow should look like this example:
Referencing a case from a data flow
Finally, you need to reference the Contact Customer case from the Call Detail Record data flow. This case is triggered for each customer who has more than two dropped calls within a week.
- In the Call Detail Record data flow, click the Destination shape.
- From the Destination drop-down menu, select .
- From the Case drop-down menu, select .
- Click .
When you finish this task, the complete Call Detail Record data flow should look like this example:
Creating a real-time run of a data flow
Now your tutorial is almost completed. You can create a real-time run of the Call Detail Record data flow that uses the newly created DroppedCallsDetection event strategy.
- Open the Call Detail Record data flow.
- Click and select .
- In the Data Flow Test Run dialog box, click .
After you create the real-time run of the data flow, you need to feed data to the CDR Stream data set.
Open the CDR Stream data set.
Use one of the available services to populate the CDR Stream data set with call detail records.
Some web browsers allow you to use free extensions to construct WebSocket requests or HTTP requests. You can use these extensions to deliver data to the CDR Stream.
- Click to check the payload format that you need to use in the WebSocket requests or HTTP requests.
As soon as you create the data flow run and feed data to the stream data set, the data set starts to deliver the call detail records to the data flow. The event strategy identifies customers who have more than two dropped calls within a week and the data flow triggers the case for each of the customers.
Click Call Detail Record data flow. In the Data Flow Run window, you can view details of the run.
> > > > and open thePrevious topic Using event strategy in Pega 7 Platform real-time event processing (7.2.2) Next topic Troubleshooting decision management components