1. 程式人生 > 其它 >如何使用 SAP Kyma 控制檯手動傳送 SAP Commerce Cloud Mock 應用暴露的事件

如何使用 SAP Kyma 控制檯手動傳送 SAP Commerce Cloud Mock 應用暴露的事件

網址:https://developers.sap.com/tutorials/cp-kyma-microservice-trigger.html

本地路徑:
C:\Code\referenceCode\SAP Kyma教程例子\api-mssql-go

(1) This tutorial relies on the Commerce mock application to publish events into the Kyma runtime.

(2) bind the Commerce mock application to the dev Namespace

(3) we will create a service instance of the SAP Commerce Cloud - Events.

(4) The service instance will allow for any microservice or lambda function within the dev Namespace to subscribe to these events by defining an event subscription.

藉助這個 mock 應用的 service instance,我們可以讓 dev 名稱空間的任何微服務或者Lambda Function,訂閱 service instance 暴露出的事件。

The subscription pairs an event source, the Commerce mock application, and the event type, order.created, to a subscriber.

訂閱實際上是一個抽象,包含了事件源,mock 應用,和訂閱事件型別。

這個訂閱的原始碼,用 yaml 檔案定義如下:

apiVersion: eventing.kyma-project.io/v1alpha1
kind: Subscription
metadata:
  name: api-mssql-go-event-sub
spec:
  filter:
    filters:
    - eventSource:
        property: source
        type: exact
        value: ""
      eventType:
        property: type
        type: exact
        value: sap.kyma.custom.mp-commerce-mock.order.created.v1
  protocol: ""
  protocolsettings: {}
  sink: http://api-mssql-go.dev.svc.cluster.local:80/orderCodeEvent 

在cmd/api/main.go 裡,為 /orderCodeEvent 這個 endpoint,註冊一個處理函式:ConsumeOrderCode

bind the mock application to the dev Namespace. This process is used to enable the usage of the APIs and events of the mock application to the bounded Namespace.

把 mock 應用繫結到 dev namespace,這樣才能讓該名稱空間的應用,消費這個 mock 應用暴露出的事件。

也要為 mock 應用暴露出的 event,建立一個 instance.

點選 dev namespace,進入 Service Management -> Catalog, 選擇 mp-commerce-mock 應用:

選擇該 mock 應用 service plan 中的 SAP Commerce Cloud - Events:

點 Add 按鈕,建立新的例項:

測試

在 API rules 裡,點選 commerce-mock 的 host 超連結:

https://commerce.c-46d70f2.kyma.shoot.live.k8s-hana.ondemand.com/

選擇 remote API:

選擇 SAP Commerce Cloud - Events:

Event topic 下拉列表裡,選擇 order.created.v1,再點選 Send Event 即可:

更多Jerry的原創文章,盡在:"汪子熙":