网址: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/v1alpha1kind: Subscriptionmetadata: name: api-mssql-go-event-subspec: 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.http://c-46d70f2.kyma.shoot.live.k8s-hana.ondemand.com/
选择 remote API:
选择 SAP Commerce Cloud - Events:
Event topic 下拉列表里,选择 order.created.v1,再点击 Send Event 即可:
联系客服