Experimenting with event windows
6 Tasks
20 mins
Pega Platform '24.2
Beginner
Pega Platform '24.2
English
Scenario
In the Sample application, the Sample-Data-Window Class uses the following data structure:
Field | Type | Description |
---|---|---|
EventID |
Identifier |
A unique identifier that makes every incoming record unique. |
EventKey |
Text |
A key field that is used to group the incoming events. |
EventType |
Text |
A field that can hold text values. |
EventValue |
Integer |
A field that can hold integer values. |
Create three Event Strategies in the Sample-Data-Window Class to experiment with different Event Window options.
Use the following credentials to log in to the exercise system:
Role | User name | Password |
---|---|---|
System architect | SystemArchitect | rules |
Your assignment consists of the following tasks:
Task 1: The Tumbling Event Window Event Strategy
Create a new Event Strategy in the Sample-Data-Window Class named Tumbling Event Window. Configure the Event Strategy:
- Use the Event Key field as the Event Key.
- Add a Window component that uses a Tumbling Window with the size of 3 events.
- Add an Aggregate component that counts the number of events as "CountOfEvents".
- Emit the event as it happens.
Task 2: Test the Tumbling Event Window Event Strategy
Run the Event Strategy with the Tumbling Window to test its behavior.
Task 3: The Sliding Event window Event Strategy
Create a copy of the Tumbling Event Window Event Strategy named Sliding Event Window and update the Window component to use a Sliding Window with the size of 3 events.
Task 4: Test the Sliding Event Window Event Strategy
Run the Event Strategy with the Sliding Window to test its behavior.
Task 5: The Landmark Event Window Event Strategy
Create a copy of the Sliding Event Window Event Strategy named Landmark Event Window and update the Window component to use a Landmark Window with the size of 3 events.
Task 6: Test the Landmark Event Window Event Strategy
Run the Event Strategy with the Landmark Window.
Challenge Walkthrough
Detailed Tasks
1 The Tumbling Event Window Event Strategy
- Log in as the system architect:
- In the User name field, enter SystemArchitect.
- In the Password field, enter rules.
- In the navigation pane of Dev Studio, click App to open the Application Explorer.
- In the Application Explorer, search for the Sample-Data-Window Class.
- In the Application Explorer, right-click on the Sample-Data-Window Class, and then click Create > Decision> Event Strategy.
- On the Create Event Strategy tab, create a new Event Strategy:
- In the Label field, enter Tumbling Event Window.
- In the upper-right corner, click Create and open.
- On the Edit Event Strategy: Tumbling Event Window rule form, double-click on the Real-time data component to set up the Real-time data properties:
- In the Event key list, select EventKey.
- In the Event timestamp section, confirm that the System time radio button is selected.
- Click Submit.
- On the canvas, on the right side of the first shape, click the + icon and add a new Window component.
- On the canvas, double-click on the Window component to set up the Window properties.
- In the Window section, confirm that the Tumbling radio button is selected.
- In the Count for field, enter 3 and then select Events in the drop-down list.
- Click Submit.
Tip: The Event Strategy will continue processing until the end of the window. This can be the number of events that are processed or a given period. The Event Strategy emits no events until the window is complete. In this case, the event strategy will compute until it receives three events. Once it receives three events, it emits its results, and the Event Strategy processes new events because the count of events is reset to zero.
- On the canvas, on the Window shape, click Add > Aggregate to add a new Aggregate component.
- On the canvas, double-click on the Aggregate component to set up the Aggregate properties:
- In the Aggregations section, click Add aggregation.
- In the first list, select Count.
- In the Aggregate column, enter CountOfEvents.
- Click Submit.
- On the canvas, double-click on the Emit component to review the Emit properties.
- In the Emit event list, confirm that As it happens is selected.
Tip: When the As it happens option is selected, the events and all calculated fields are emitted as soon as they occur. The Only once option lets you emit events in a given time interval.
- Click Submit.
- In the Emit event list, confirm that As it happens is selected.
- In the upper-right corner, click Save.
2 Test the Tumbling Event Window Event Strategy
- On the Event Strategy: Tumbling Event Window rule form, in the upper-right corner, click Actions > Run to open the run window.
- In the Run window, complete the following actions:
- In the EventKey field, enter any value, for example, Key-1.
Note: The Event Key field is used to group the incoming events. You can add additional keys in the Window component.
- In the upper-right corner, click Run to send an event to the Event Strategy.
Note: In this case, because the window is configured to tumble after three events are received, the Simulate system time field has no importance. If the window was set to tumble after a specific duration, then the Simulate system time field has importance. The system uses the Simulate system time field to calculate when the window tumbles.
- In the EventKey field, enter any value, for example, Key-1.
- Analyze the results:
- The Sent events (1) section now has a single page. This section displays the values for each event that was received.
- The window tumbles to the next window once the event strategy receives three events. Until then, it continues processing. This is why the Emitted events (0) section currently has no values.
- In the upper-right corner, click Run to send a second event to the Event Strategy.
- The Sent events (2) section now has now two pages.
- The window tumbles to the next window once the event strategy receives three events. Until then it will continue processing. This is why the Emitted events (0) section currently has no values.
- In the upper-right corner, click Run to send a third event to the Event Strategy.
- The Sent events (3) section now has now three pages.
- The Emitted events (1) section has one event emitted. Note that the aggregate variable, CountOfEvents is 3.
- The window tumble condition of "three events" is now fulfilled, so the next window is started. Until then it will continue processing. This is why the Emitted events (0) section currently has no values.
- In the upper-right corner, click Run to send a fourth event to the Event Strategy.
- The Sent events (4) section now has now four pages.
- The Emitted events (1) section has still one event, and no other event was emitted.
3 The Sliding Event window Event strategy
- On the Event Strategy: Tumbling Event Window rule form, in the upper-right corner, click Save as to create a new Event Strategy.
- In the Label field, enter Sliding Event Window.
- In the upper-right corner, click Create and open.
- On the Edit Event Strategy: Sliding Event Window rule form, update the Event Strategy.
- On the canvas, double-click on the Window component to set up the Window properties.
- In the Window field, select Sliding.
- In the Look for last field, enter 3 and select Events.
- Click Submit.
- In the upper-right corner, click Check in.
- In the Check In window, in the Check-in comments field enter any comment, then click Check in.
4 Test the Sliding Event Window Event Strategy
- On the Event Strategy: Sliding Event Window rule form, in the upper-right corner, click Actions > Run to open the Run window.
- In the Run window, complete the following actions:
- In the EventKey field, enter any value, for example, Key-2.
- In the upper-right corner, click Run to send an event to the Event Strategy.
Tip: Because the Window component is configured to Slide, the system always looks at the last 3 events.
- Analyze the results:
- The Sent events (1) section now has a single page.
- The Emitted events (1) section has one event emitted. As soon as the first event is received, it is emitted. This is because there are no defined filters in the Event Strategy, and the Emit component is set to emit the event As it happens. Note that the CountOfEvents is set to 1.
- In the upper-right corner, click Run to send a second event to the Event Strategy.
- The Sent events (2) section now has now two pages.
- The Emitted events (2) section has another event that is emitted. As soon as the Event Strategy receives the second event, it is emitted.
- Note that the aggregate variable, CountOfEvents is now set to 2.
- In the upper-right corner, click Run to send a third event to the Event Strategy.
- The Sent events (3) section now has now three pages.
- The Emitted events (3) section has three events emitted.
- Note that the aggregate variable, CountOfEvents is 3.
- In the upper-right corner, click Run to send a fourth event to the Event Strategy.
- The Sent events (4) section now has now four pages.
- The Emitted events (4) section has four events emitted.
- Note that the aggregate variable, CountOfEvents is still 3. This is because the event strategy calculates for the last 3 events. There are now four events, and the first event is lost.
5 The Landmark Event window Event Strategy
- On the Event Strategy: Sliding Event Window rule form, in the upper-right corner, click Save as to create a new Event Strategy.
- In the Label field, enter Landmark Event Window.
- In the upper-right corner, click Create and open.
- On the Edit Event Strategy: Landmark Event Window rule form, double-click on the Window component to set up the Window properties.
- In the Window field, select Landmark.
- Click Submit.
- In the upper-right corner, click Check in.
- In the Check In window, in the Check-in comments field enter any comment, then click Check in.
6 Test the Landmark Event Window Event Strategy
- On the Event Strategy: Landmark Event Window rule form, in the upper-right corner, click Actions > Run to open the run window.
- On the Run window, complete the following actions:
- In the EventKey field, enter any value, for example, Key-3.
- In the upper-right corner, click Run to send an event to the Event Strategy.
Tip: Because the Window is configured as Landmark, the system continues to process events.
- Analyze the results:
- The Sent events (1) section now has a single page.
- The Emitted events (1) section has one event emitted. As soon as the Event Strategy receives the first event, it is emitted, because the Emit component is set to emit the event As it happens.
- Note that the CountOfEvents is set to 1.
- In the upper-right corner, click Run to send a second event to the Event Strategy.
- The Sent events (2) section now has two pages.
- The Emitted events (2) section has another event that is emitted. As soon as the second event is received, it is emitted.
- Note that the aggregate variable, CountOfEvents is 2.
- In the upper-right corner, click Run to send a third event to the Event Strategy.
- The Sent events (3) section now has now three pages.
- The Emitted events (3) section has three events emitted.
- Note that the aggregate variable, CountOfEvents is 3.
- In the upper-right corner, click Run to send a fourth event to the Event Strategy.
- The Sent events (4) section now has now four pages.
- The Emitted events (4) section has four events emitted.
- Note that the aggregate variable, CountOfEvents is still 4. This is because the event strategy continues to calculate all incoming events.
This Challenge is to practice what you learned in the following Module:
Available in the following mission:
If you are having problems with your training, please review the Pega Academy Support FAQs.
Want to help us improve this content?