Handle evolving formats by using a schema registry

Scenario

The customer satisfaction team wants to respond to customers who cancel their orders in the moment, to attempt to convert some of these cancellations into new orders. For example, they are considering promptly reaching out to customers who cancel an order because they changed their mind, with voucher codes or information about similar products.

The format of events on this topic is expected to evolve over time, so the customer satisfaction team will connect Event Processing to the schema registry to continue to process without errors.

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 might differ from the current interface if you are using a newer version.

  • Event Streams 11.5.0
  • Event Processing 1.2.0

Instructions

Step 1 : Discover the topic to use

For this scenario, you need a source of order cancellation events.

  1. Go to the Event Streams topics page.

    screenshot

    If you need a reminder of how to access the Event Streams web UI, you can review Accessing the tutorial environment.

  2. Find the CANCELLATIONS.REG topic.

    screenshot

    Click into the topic to review the events that are available here.

Tip: Keep the Event Streams UI open. It is helpful to have the topic available while you start to work on your Event Processing flows, as you can refer to the connection information for the cluster as you work. Complete the following steps in a separate browser window or tab.

  1. Go to the Event Streams schema registry page.

    screenshot

  2. Find the CANCELLATIONS.REG-value schema.

    screenshot

    Click into the schema to review the format of events on the CANCELLATIONS.REG topic.

Tip: Keep the Event Streams UI open. It is helpful to have the schema available while you start to work on your Event Processing flows, as you can refer to the event information as you work. Complete the following steps in a separate browser window or tab.

Step 2 : Create a flow

  1. Go to the Event Processing home page.

    screenshot

    If you need a reminder about how to access the Event Processing home page, you can review Accessing the tutorial environment.

  2. Create a flow, and give it a name and description to explain that you will use it to create a stream of order cancellation events.

    screenshot

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.

  1. Update the Event source node.

    screenshot

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

  2. Add a new event source.

    screenshot

    Click Next.

  3. Get the server address for the topic from the Event Streams topic page.

    screenshot

    As Event Streams is in the same cluster as Event Processing, you can use the internal listener for this.

    Click the Copy icon next to the Internal listener address to copy the address to the clipboard.

  4. Configure the new event source.

    screenshot

    Paste the server address that you copied from Event Streams in the previous step, and click Next.

  5. Copy the username and password from Event Endpoint Management and paste into Event Processing to allow access to the topic.

    screenshot

    The username starts with eem-.

    Click Next.

    If you need a reminder of the password for the kafka-demo-apps user, you can review the Accessing Kafka topics.

  6. Select the CANCELLATIONS.REG topic.

    screenshot

  7. Click Next. The Message format pane is displayed.

    The format Avro (schema registry) is auto-selected in the Message format drop-down.

    screenshot

  8. Get the schema registry endpoint URL from Event Streams.

    screenshot

    Click the Copy icon in the Schema registry endpoint section to copy the endpoint URL to the clipboard.

  9. Paste the schema registry endpoint URL into the Schema registry URL box. Append /apis/ccompat/v6 to the end of the URL.

    screenshot

  10. Use the same username and password for the kafka-demo-apps user for accessing the schema registry.

  11. Click Next to auto-populate the Avro schema in the Avro schema field.

    The information in the schema enables Event Processing to give guidance for creating Event Processing nodes.

    Click Next.

  12. In the Key and headers pane, click Next.

    screenshot

    Note: The key and headers are displayed automatically if they are available in the selected topic message.

  13. In the Event details pane, enter the node name as cancellations in the Node name field.

    screenshot

  14. Set the lateness to 0.

    screenshot

  15. Click Configure to finalize the event source.

Step 4 : Test the flow

The next step is to run your Event Processing flow and view the results.

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

screenshot

Click Stop after you have reviewed the events.

Step 5 : Filter to events of interest

The next step is to identify cancellations where the customer changed their mind.

  1. Create a Filter node and link it to the event source node.

    screenshot

    Create a filter node by dragging one onto the canvas. You can find the filter node 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.

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

  2. Give the filter node a name that describes the events it should identify: customer changed their mind.

    screenshot

    Click Next.

  3. Define a filter that matches cancellations events with a reason value that equals CHANGEDMIND.

    screenshot

    Click Add to expression.

  4. Click Configure to finalize the filter.

Step 6 : Test the flow

The final step is to run your Event Processing flow and view the results.

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

screenshot

Verify that all events are for cancellation events with a reason of CHANGEDMIND.

Recap

You used a schema registry in the event source node to dynamically provide schemas for a stream of events. This means that your Event Processing flow will continue to process if a compatible change is made to the schema for future events on the topic.