日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

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

發布時間:2023/12/19 数据库 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 在 SAP BTP Kyma Runtime 上使用 Redis 读取和存储数据 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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 上:

  • 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 去。

  • 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 暴露給消費者。

  • 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 读取和存储数据的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。