Creating a Subscription using Kyma Eventing

Objective

After completing this lesson, you will be able to Create a subscription.

Create a Subscription

Business Scenario

After you have learned that you can subscribe to an event using the SAP BTP, Kyma runtime, you will put this knowledge into practice by subscribing to more than one event type using a Subscription custom resource. You will also trigger the events and verify that they have been delivered successfully.

Exercise Options

You can perform this exercise in two ways:

  1. Platform Simulation – follow the step-by-step instructions within the simulation.
  2. Live Environment - by using the instructions provided below, you can perform the steps in the SAP BTP Free Tier account.

Note

We recommend performing the steps in the Live Environment first.

Platform Simulation

Choose the Start Exercise button below to open a simulation of the platform. Then follow the step-by-step instructions to create a subscription using Kyma Evening.

Live Environment

In this exercise, you will perform the following steps:

  1. Set up a new namespace.
  2. Create a function using the Kyma Dashboard.
  3. Set up a subscription with various filters using the Kyma Dashboard.
  4. Trigger the workload with an event.
  5. Confirm event delivery.

Task 1: Set up a new namespace

Steps

  1. Set up a new namespace.

    In this task, you will set up a new, clean namespace with the name eventing.

    1. Create namespace eventing:

  2. Create a new function using the Kyma Dashboard.

    In this task, you will set up a new function with the name lastorder.

    1. Select the namespace that you just set up.

    2. Navigate to Workloads / Functions and select Create Function:

    3. Insert the parameters as follows:

    4. Choose Create.

    5. On the dashboard you will receive, choose Edit as you want to replace the source of the function's editor:

    6. In the Edit window, insert this code:

      Code Snippet
      Copy code
      Switch to dark mode
      123456
      module.exports = { main: async function (event, context) { console.log("Received event:", event.data); return; } }
    7. Choose Update:

    8. After some seconds, your function should be running, and it will look as follows:

  3. Set up a subscription with various filters using the Kyma Dashboard.

    In this task, you will create a subscription CR and thus, subscribe to the events order.received.v1 and order.changed.v1:

    1. Navigate to workloads / functions and select the menu Configuration. Here, choose Create Subscription.

    2. Configure the subscription window with the following parameters (here you have to add another filter):

      • Name: lastorder-sub
      • Service: lastorder
    3. For the filters, insert the following parameters.

      • Filter 1: sap.kyma.custom.myapp.order.received.v1
      • Filter 2: sap.kyma.custom.myapp.order.changed.v1
    4. Choose Create.

    5. After some seconds, your subscription is ready and will look as follows:

  4. Trigger the workload with an event.

    In this task, you will publish the events order.received.v1 and order.changed.v1 and trigger the function.

    Note

    For specifying the event payload, you can send events based on the CloudEvents specification. Various SDKs are also available, so that you could publish/emit and subscribe/consume them in your custom applications written in a variety of different programming languages.
    1. Open a terminal window and run:

      Code Snippet
      Copy code
      Switch to dark mode
      1
      kubectl -n kyma-system port-forward service/eventing-event-publisher-proxy 3000:80
    2. Open another terminal window and run the following in order to publish the event order.received.v1 and trigger the function:

      Code Snippet
      Copy code
      Switch to dark mode
      1
      curl -v -X POST -H "ce-specversion: 1.0" -H "ce-type: sap.kyma.custom.myapp.order.received.v1" -H "ce-source: myapp" -H "ce-eventtypeversion: v1" -H "ce-id: cc99dcdd-6f6d-43d6-afef-d024eb276584" -H "content-type: application/json" -d "{\"orderCode\":\"3211213\", \"orderStatus\":\"received\"}" http://localhost:3000/publish
    3. In the same terminal window, run the following in order to publish the event order.changed.v1 and trigger the function:

      Code Snippet
      Copy code
      Switch to dark mode
      1
      curl -v -X POST -H "ce-specversion: 1.0" -H "ce-type: sap.kyma.custom.myapp.order.changed.v1" -H "ce-source: myapp" -H "ce-eventtypeversion: v1" -H "ce-id: 94064655-7e9e-4795-97a3-81bfd497aac6" -H "content-type: application/json" -d "{\"orderCode\":\"3211213\", \"orderStatus\":\"changed\"}" http://localhost:3000/publish
  5. Confirm event delivery

    In this task, you will make sure that the events you just triggered were successfully delivered.

    1. On the Kyma Dashboard on the SAP BTP, navigate to Workloads / Functions. Choose your function lastorder:

    2. Scroll down to the section Replicas of the Function and choose the name:

    3. In the section Containers, choose View Logs:

    4. If the events were delivered successfully, they will appear in the logs as follows:

Result

Congratulations! You have successfully completed this exercise about Kyma Eventing on the SAP BTP, Kyma runtime. You were able to create a subscription that subscribes to various event types and trigger the workload with an event.

Log in to track your progress & complete quizzes