Generating custom properties for custom filters

Writing custom filter expressions that use dynamically generated properties added to events can help to identify specific situations.

Scenario

In this scenario, the EMEA operations team wants to move away from reviewing quarterly sales reports and start to look for high-value orders in their region as they occur throughout the quarter.

Identifying large orders as they occur will help the team identify as early as possible any changes they need to make to sales forecasts. This information can then be fed back into their manufacturing cycle.

Before you begin

The instructions in this tutorial use the Tutorial environment, which includes a selection of topics each with a live stream of events, created to allow you to explore features in IBM Event Automation. Following the setup instructions to deploy the demo environment gives you a complete instance of IBM Event Automation that you can use to follow this tutorial for yourself.

Versions

This tutorial uses the following versions of Event Automation capabilities. Screenshots can differ from the current interface if you are using a newer version.

  • Event Streams 11.3.1
  • Event Endpoint Management 11.1.5
  • Event Processing 1.1.5

Instructions

Step 1 : Discover the topics to use

For this scenario, you need a source of order events. A good place to discover sources of event streams to process is the catalog, so start there.

  1. Go to the Event Endpoint Management catalog.

    screenshot

    If you need a reminder about how to access the Event Endpoint Management catalog you can review Accessing the tutorial environment.

    If there are no topics in the catalog, you need to complete the tutorial setup step to populate the catalog.

  2. The Orders topic contains events about orders that are made.

    screenshot

Step 2 : Provide a source of events

The next step is to create an event source in Event Processing for the topic to use in the flow.

Use the server address information and Generate access credentials button on the topic page in the catalog to define an event source node.

screenshot

Tip: If you need a reminder on how to create an event source node, you can follow the Identify orders from a specific region tutorial.

Step 3 : Calculate order totals

The next step is to calculate the total value of each order, that you will use to identify the high-value orders.

  1. Create a Transform node.

    screenshot

    Create a transform node by dragging one onto the canvas. You can find this in the Processors section of the left panel.

    Click and drag from the small gray dot on the event source to the matching dot on the transform node.

  2. Hover over the transform node and click Edit icon Edit to configure the node.

    Call the transform node Calculate order total.

    screenshot

  3. Create a new property called order total.

    screenshot

    An order event includes the unit cost of an item, and the quantity of items in the order. The order total can be computed by multiplying these two numbers.

    Suggested value for the property:

    quantity * price
    
  4. You can leave the other event properties as they are.

  5. Click Configure to finalize the transform.

Step 4 : Identify high-value EMEA orders

The next step is to filter the stream of events based on this new total order value property to select the high value EMEA orders.

  1. Add a Filter node.

    screenshot

    Create a filter node by dragging one onto the canvas. You can find this in the Processors section of the left panel.

    Click and drag from the small gray dot on the event source to the matching dot on the filter node.

    Did you know? Instead of dragging the node, you can add a node onto the canvas and automatically connect it to the last added node by double-clicking a node within the palette. For example, after configuring an event source node, double-click any processor node to add and connect the processor node to your previously configured event source node.

  2. Hover over the filter node and click Edit icon Edit to configure the node.

    Name the filter node to show that it is going to select high value EMEA orders.

  3. Use the assistant to start a filter based on orders with an order total greater than 575.

    screenshot

  4. Click Add to expression.

  5. Edit the filter so that it also only matches orders that are made in the EMEA region.

    screenshot

    Suggested value for the filter expression:

    `order total` > 575 AND region = 'EMEA'
    
  6. Click Configure to finalize the filter.

Step 5 : Test the flow

The final step is to run your event processing flow and view the results.

  1. Use the Run menu, and select Include historical to run your filter on the history of order events available on this Kafka topic.

  2. Click the Filter node to see a live view of results from your filter. It is updated as new events are emitted onto the orders topic.

    screenshot

  3. When you have finished reviewing the results, you can stop this flow.

Recap

You used a transform node to dynamically compute additional properties in the events.

You also used a filter node to specify a custom, complex expression - more detailed than the simple expressions created by using the Assistant.