https://developers.sap.com/tutorials/cp-kyma-redis-function.html

This sample provides a Redis deployment and two serverless functions that interact with it.

这个例子提供了一个 Redis 应用部署和两个使用 Redis 的 serverless 函数。

The function cache-order will be set to subscribe to an order.created event provided by the Commerce mock application.

Commerce Mock 应用有一个 order.created 事件,cache-order 函数订阅这个事件。

Once triggered, the function will perform an API call to the Commerce mock to obtain additional details regarding the order and then cache the information into Redis.

一旦 order.created 事件触发,cache-order 函数响应该事件,调用一个 Commerce Mock API,读取创建订单的更多明细,然后将数据存储到 Redis 里。

The function get-order, exposed as an API, is used to then retrieve the order details from the Redis cache.

函数 get-order, 以 API 的形式暴露,负责从 Redis cache 里读取订单明细。

从这个Github仓库里下载 sample 代码。

进入 Kyma 控制台,点击 Create Binding:

In this step, you will bind the Commerce Mock application to the dev namespace. This will allow the APIs and Events of the mock application to be used within the namespace.

这一步会将 Commerce Mock 应用同 dev 命名空间绑定在一起,这使得 Mock 应用的 API 和 Events 能够在 dev 命名空间内被使用。

点击 Create:

Create the Events service instances - 创建事件服务实例

In this step, you will create service instances of the Events the Commerce Mock application exposes. This will allow the events to be consumed from resources within the namespaces such as functions or microservices.

创建 Commerce Mock 应用暴露的事件的服务实例。这样,dev 命名空间下的资源,比如 functions 和 microservices 就能够消费这些事件。

选择 commerce-mock:

选择 SAP Commerce Cloud - Events:

点击 Add 按钮,创建一个 Service 实例:

创建好的 service 实例:

Step 4: Create API service instances

In this step, you will create a service instance of the Commerce Webservices the Mock application exposes.

Mock Application 暴露的 Commerce Web Service, 可以基于其创建服务实例。该服务实例能够将 API 暴露给同一命名空间下的其他资源,比如函数和微服务。

查看两个成功创建的服务实例:

下一步,部署三个资源到 Kyma 上:

  1. cache-order: This function will subscribe to an event published by the Commerce mock application. Once triggered, it will call back to the Commerce mock application to obtain the totalPriceWithTax and then cache the information into Redis.

该函数订阅 Commerce Mock Application 暴露的 order.created 事件。该事件发生后,cache-order 函数调用 Commerce mock Application,获得 totalPriceWithTax,然后存储到 Redis 去。

  1. get-order: This function will be exposed as an API allowing retrieval of data stored within the Redis cache.

Redis cache 里通过 cache-order 存储的订单信息,通过 get-order 暴露给消费者。

  1. redis-deployment: This deployment defines the Redis cache configuration and the associated Kubernetes service which exposes the Redis instance to the two Serverless functions.

这个 deployment 定义了 Redis cache 配置信息,以及关联的 Kubernetes Service, 后者将 Redis 实例暴露给(1)(2) 两个 serverless 函数使用。

依次将 k8s 文件夹下的 yaml 文件进行部署:

确保 deployment 状态全部为 Running:

Add event subscription to function

In this step, you will configure the function cache-order, deployed in the previous step, to run when the order.created event is fired from the Commerce Mock application.

这一步,将 cache-order 订阅到 order.created 事件上。

从 functions 列表里找到 cache-order:

创建一个事件订阅 Event subscription:

cache-order function 需要调用对应的 API,因此需要为其创建 service binding.

通过这个 Service Binding,就可以借助该 Service Instance,调用 Commerce Webservice了:

对 function 代码进行微调

找到环境变量里包含 GATEWAY_URL 的变量:

点击 commerce-mock 的 host 超链接,手动触发一个 order.created 事件。

点击 Remote API:

找到 SAP Commerce Cloud - Events:

点击按钮 Send Event,模拟发送一个 order.created 事件,payload 里包含的 orderCode 为 76270000:

事件成功发送:

在 cache-order 的 logs 面板里,果然看到了订单 code 76270000 对应的处理日志:

下一步,再试试 get-order 函数,是否能够从 Redis cache 中读取订单信息。

点击这个超链接:https://get-order.c-46d70f2.kyma.shoot.live.k8s-hana.ondemand.com/

会收到如下错误消息:“error”: “No orderCode received!”

这是因为我们尚未为该 serverless function 指定 orderCode.

试试在 url 后手动加上 orderCode:

https://get-order.c-46d70f2.kyma.shoot.live.k8s-hana.ondemand.com/?orderCode=76270000

现在就能够正常工作了。

更多Jerry的原创文章,尽在:“汪子熙”:

在 SAP BTP Kyma Runtime 上使用 Redis 读取和存储数据相关推荐

  1. 一步步将 SAP Commerce Mock 应用部署到 SAP BTP Kyma Runtime

    The Kyma mock application contains lightweight substitutes for SAP applications to ease the developm ...

  2. SAP BTP Kyma Runtime dashboard 打开报缺少缺陷的错误消息该如何解决

    登录 SAP BTP 测试帐号,确保 Entitlements->Service Assignments 下有一个 Kyma runtime,类型为 trial environment: 点击 ...

  3. 一步步把 SAP UI5 应用部署到 SAP BTP Kyma 运行环境中去

    这是 Jerry 2021 年的第 40 篇文章,也是汪子熙公众号总共第 317 篇原创文章. Jerry 2018年曾经写过两篇文章,介绍了如何在 Kubernetes 这个容器编排平台上运行一个包 ...

  4. mysql安装在磁盘阵列上_MySql安装在服务器磁盘C上,如何设置把存储数据存放到磁盘阵列里。...

    www.shufadashi.com防采集. 数据文件想存储在SAN里,不存放在默认安装路径下....数据文件想存储在SAN里,不存放在默认安装路径下.展开. 服务器和磁盘阵列2113的链接有很多种方 ...

  5. 在 SAP BTP 上体验 SAP HANA Cloud 试用版本

    这是 Jerry 2021 年的第 58 篇文章,也是汪子熙公众号总共第 335 篇原创文章. 我们在 SAP 官方网站 help.sap.com 输入关键字 SAP HANA 之后: 会看到很多搜索 ...

  6. redis介绍命令性能数据及监控缓存穿透

    上一章: linux安装部署redis&配置远程连接_傲娇的喵酱的博客-CSDN博客 一.redis介绍 Redis是C语言写的,官方提供的数据为100000+的QPS(每秒查询率) Redi ...

  7. SAP HANA Cloud 学习教程之二: 如何往SAP BTP 上 HANA Cloud 实例的数据库表里插入数据

    这个教程的前一篇文章,SAP HANA Cloud 学习教程之一: 如何在 SAP BTP 上创建 SAP HANA Cloud 实例,我们已经成功在 SAP BTP HANA Cloud Servi ...

  8. SAP BTP 上使用 Mobile Back-End Tools(MBT)进行全栈开发的方法概述

    Understand Full-Stack Development with Mobile Back-End Tools 从本质上讲,MBT 是一组工具,可让您无需编写一行代码即可生成功能齐全的 OD ...

  9. 如何将SAP API Hub 上提供的工作流导入到 SAP BTP 上

    官网链接:https://developers.sap.com/tutorials/cp-starter-ibpm-employeeonboarding-2-configure.html SAP Wo ...

最新文章

  1. Git与Repo入门
  2. RMQ问题(区间求最值)
  3. 海思芯片怎么使用tde给qt加速_基于Hisi芯片,交叉编译、移植Qt4.8.6(可旋转)
  4. Android窗口管理服务WindowManagerService的简要介绍和学习计划
  5. 大端字节序码流中取出2字节_产生字节码
  6. java经典设计模式4,JAVA设计模式(4) 之装饰设计模式
  7. 前端学习(1289):nodejs模块化的开发规范
  8. js 简单弹框toast
  9. Laravel核心解读 -- Request
  10. 使用Express搭建Web服务器
  11. oracle 改变受限模式,oracle之受限模式修改
  12. 计算机网络中的HTML,计算机网络分类有哪些
  13. 程炳皓:我不恨陈一舟 开心网做不好是我自己的问题
  14. 万年历(hao123)代码
  15. ESLint Prettier
  16. sql2java-excel(二):基于apache poi实现数据库表的导出的spring web支持
  17. 运动世界校园显示服务器开小差,你的跑步成绩无效,是否申请成绩异常?
  18. 兼容iOS 10 _升级xcode8_适配(四)
  19. 网络安全--主机探测教程
  20. 制作黑苹果安装U盘(Clover+OC+PE)三引导

热门文章

  1. 2.Nginx学习-The HTTP Core module
  2. 适时选择getDeclaredxxx和getxxx
  3. #11 硬连接与软链接与RAID与LVM2
  4. 【风马一族_php】NO4_php基础知识
  5. I00029 C语言程序-打印九九乘法表
  6. 带标题和导航点的ViewPager
  7. ASP.NET 2.0 中的代码隐藏和编译
  8. 有关 MyEclipse-export runnable jar file选项 launch configuration里面没有可以选择的东西的解决方法...
  9. 处理本地能登陆mysql但navicat连接不上的问题
  10. nth_element(a+1 , a + m, a + n+1);