Skip to content

创建一个RabbitMQSource

stage version

本节介绍如何创建RabbitMQSource。

先决条件

  1. 您已经安装了Knative事件
  2. 您已经安装了CertManager v1.5.4—与RabbitMQ消息拓扑操作器最简单的集成
  3. 您已经安装了RabbitMQ消息拓扑操作器-我们的建议是最新版本与CertManager
  4. 一个正在工作的RabbitMQ实例,我们建议使用RabbitMQ集群操作符创建一个.有关配置RabbitmqCluster CRD的更多信息,请参见RabbitMQ网站

安装RabbitMQ控制器

  1. 运行以下命令安装RabbitMQSource控制器:

    kubectl apply -f https://storage.googleapis.com/knative-nightly/eventing-rabbitmq/latest/rabbitmq-source.yaml
    
  2. 验证rabbitmq-controller-managerrabbitmq-webhook正在运行:

    kubectl get deployments.apps -n knative-sources
    

    Example output:

    NAME                           READY   UP-TO-DATE   AVAILABLE   AGE
    rabbitmq-controller-manager     1/1     1            1           3s
    rabbitmq-webhook                1/1     1            1           4s
    

创建服务

  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
    

创建一个RabbitMQSource对象

  1. 使用以下模板创建一个YAML文件:

    apiVersion: sources.knative.dev/v1alpha1
    kind: RabbitmqSource
    metadata:
      name: <source-name>
    spec:
      rabbitmqClusterReference:
        # Configure name if a RabbitMQ Cluster Operator is being used.
        name: <cluster-name>
        # Configure connectionSecret if an external RabbitMQ cluster is being used.
        connectionSecret:
          name: rabbitmq-secret-credentials
      rabbitmqResourcesConfig:
        parallelism: 10
        exchangeName: "eventing-rabbitmq-source"
        queueName: "eventing-rabbitmq-source"
      delivery:
        retry: 5
        backoffPolicy: "linear"
        backoffDelay: "PT1S"
      sink:
        ref:
          apiVersion: serving.knative.dev/v1
          kind: Service
          name: event-display
    
    Where:

    • <source-name> 是你想要的RabbitMQSource对象的名称。
    • <cluster-name> 是你之前创建的RabbitMQ集群的名称。

    Note

    您不能同时设置nameconnectionSecret,因为name是针对与Source运行在同一集群中的RabbitMQ集群操作实例,而connectionSecret是针对外部RabbitMQ服务器。

  2. 运行以下命令应用YAML文件:

    kubectl apply -f <filename>
    
    其中<filename> 是您在上一步中创建的文件的名称。

验证

检查事件显示服务,看它是否正在接收事件。 Source开始向Sink发送事件可能需要一段时间。

  kubectl -l='serving.knative.dev/service=event-display' logs -c user-container
  ☁️  cloudevents.Event
  Context Attributes,
    specversion: 1.0
    type: dev.knative.rabbitmq.event
    source: /apis/v1/namespaces/default/rabbitmqsources/<source-name>
    subject: f147099d-c64d-41f7-b8eb-a2e53b228349
    id: f147099d-c64d-41f7-b8eb-a2e53b228349
    time: 2021-12-16T20:11:39.052276498Z
    datacontenttype: application/json
  Data,
    {
      ...
      Random Data
      ...
    }

清理

  1. 删除RabbitMQSource:

    kubectl delete -f <source-yaml-filename>
    
  2. 删除RabbitMQ的证书秘密:

    kubectl delete -f <secret-yaml-filename>
    
  3. 删除事件显示服务:

    kubectl delete -f <service-yaml-filename>
    

额外信息

Back to top

We use analytics and cookies to understand site traffic. Information about your use of our site is shared with Google for that purpose. Learn more.

× OK