跳至內容

建立 RedisStreamSource

version

本主題說明如何建立 RedisStreamSource 物件。

安裝 RedisStreamSource 附加元件

RedisStreamSource 是 Knative Eventing 的附加元件。

  1. 執行以下指令安裝 RedisStreamSource

    kubectl apply -f https://github.com/knative-extensions/eventing-redis/releases/download/knative-v1.16.0/redis-source.yaml
    
  2. 驗證 redis-controller-manager 是否正在執行

    kubectl get deployments.apps -n knative-sources
    

    範例輸出

    NAME                           READY   UP-TO-DATE   AVAILABLE   AGE
    redis-controller-manager        1/1     1            1           3s
    

建立服務

  1. event-display 服務建立為 YAML 檔案

    apiVersion: serving.knative.dev/v1
    kind: Service
    metadata:
      name: event-display
      namespace: default
    spec:
      template:
        spec:
          containers:
            - # This corresponds to
              # https://github.com/knative/eventing/tree/main/cmd/event_display/main.go
              image: gcr.io/knative-releases/knative.dev/eventing/cmd/event_display
    
  2. 執行以下指令套用 YAML 檔案

    kubectl apply -f <filename>.yaml
    
    其中 <filename> 是您在上一個步驟中建立的檔案名稱。

    範例輸出

    service.serving.knative.dev/event-display created
    

  3. 執行以下指令,確保服務 Pod 正在執行

    kubectl get pods
    

    Pod 名稱以 event-display 為前綴

    NAME                                            READY     STATUS    RESTARTS   AGE
    event-display-00001-deployment-5d5df6c7-gv2j4   2/2       Running   0          72s
    

建立 RedisStreamSource 物件

  1. 使用以下 YAML 範本建立 RedisStreamSource 物件
apiVersion: sources.knative.dev/v1alpha1
kind: RedisStreamSource
metadata:
  name: <redis-stream-source>
spec:
  address: <redis-uri>
  stream: <redis-stream-name>
  group: <consumer-group-name>
  sink: <sink>

其中

  • <redis-stream-source> 是您的來源名稱。(必填)
  • <redis-uri> 是 Redis URI。請參閱 Redis 文件 以取得更多資訊。(必填)
  • <redis-stream-name> 是 Redis 串流的名稱。(必填)
  • <consumer-group-name> 是 Redis 消費者群組的名稱。如果留空,則會自動為此來源建立群組,並在此來源刪除時刪除。(選填)
  • <sink> 是要傳送事件的位置。(必填)

  • 執行以下指令套用 YAML 檔案

    kubectl apply -f <filename>
    

    其中 <filename> 是您在上一個步驟中建立的檔案名稱。

驗證 RedisStreamSource 物件

  1. 執行以下指令,檢視 event-display 事件消費者的日誌

    kubectl logs -l app=event-display --tail=100
    

    範例輸出

    ☁️  cloudevents.Event
    Validation: valid
    Context Attributes,
      specversion: 1.0
      type: dev.knative.sources.redisstream
      source: /mystream
      id: 1597775814718-0
      time: 2020-08-18T18:36:54.719802342Z
      datacontenttype: application/json
    Data,
      [
        "fruit",
        "banana"
        "color",
        "yellow"
      ]
    

刪除 RedisStreamSource 物件

  • 刪除 RedisStreamSource 物件

    kubectl delete -f <filename>
    

其他資訊

我們使用分析和 Cookie 來了解網站流量。您使用我們網站的資訊會與 Google 分享,以達到此目的。 了解更多。