Detection of key and headers in a Kafka topic message

Scenario

You must ensure timely delivery of the urgent orders originating from a specific region. To achieve that, you can use key and headers that are added to order events. Your events contain a key named countrycode and a header named priority to get started.

Key and headers

By filtering the events with the countrycode key and the priority header, you can identify urgent orders originating from a particular country. This real-time identification enables earlier adjustments to sales forecasts, facilitating the integration of these insights into your manufacturing cycle. By doing so, you can more effectively respond to demand and make necessary adjustments to your production plans.

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 Endpoint Management 11.3.2
  • Event Processing 1.2.2

Instructions

Step 1: Discover the topics to use

See the earlier filter tutorial to Discover the topic to use.

Step 2: Create a flow

See the earlier filter tutorial to Create a flow.

Step 3: Provide a source of events

The next step is to bring the stream of events you discovered in the catalog into Event Processing.

Tip: You can click Add new event source, and follow the steps under Provide a source of events to define a new event source from scratch.

  1. Repeat Steps 1-9 under Provide a source of events.

  2. In the Key and headers pane, the headers and key will be automatically populated with the key and the number of headers from the last message. Currently, there are four headers (priority, storeid, apicurio.value.globalId, and apicurio.value.encoding) and one key (key.value).

    screenshot

    Note: If the headers are not automatically populated, click the Map drop-down, and select Header to add manually. Click Edit Edit icon to change the property name and header name from the default header.name and headerName with the required values.

    screenshot

  3. In the Key and headers pane, click Edit Edit icon in the Property name column to change the default name of the key from key.value to countrycode.

    screenshot

    Click Next.

  4. In the Event details pane, select the key countrycode and the header priority checkboxes from the Property name column.

    screenshot

    Click Configure.

Step 4: Define the filter

The next step is to start processing this stream of events, by creating the filter that will select the custom subset with the events that you are interested in.

  1. Repeat Steps 1-4 under Define the filter.

  2. Use the Filter expression field to update your filter expression, for example, `countrycode` = ‘FR’ AND `priority` = ‘urgent’.

    screenshot

    Note: You must manually add the filter expression by using backticks for the property name and single quotes for the value, for example, enter `countrycode` = ‘FR’ in the Filter expression field for the complex expressions.

    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 flow menu, and select Include historical to run your filter on the history of order events available on this Kafka topic.

    screenshot

    Did you know? Include historical is useful while you are developing your flows, as it means that you don’t need to wait for new events to be produced to the Kafka topic. You can use all the events already on the topic to check that your flow is working the way that you want.

  2. A live view of results from your filter is automatically updated in real-time as new events are published onto the Orders topic.

    screenshot

  3. When you have finished reviewing the results with headers and key data, click Stop flow to stop this flow.

Recap

You have mapped key and header to the event source so that you can identify urgent orders originating from a particular region.