有没有办法为 GCP pubsub 记录 AVRO 架构

问题描述 投票:0回答:1

enter image description here像 openAPI 一样,有一种方法可以为 GCP pubsub 记录 AVRO 模式。 GCP 是否提供像 swagger UI 这样的 UI。或者这里有什么推荐。

据我所知,异步 API 可能是一个选项。但真的不确定什么是最好的解决方案

google-cloud-platform openapi avro google-cloud-pubsub asyncapi
1个回答
0
投票

您绝对可以使用 AsyncAPI,因为它与协议无关,并且允许您使用 Avro 定义有效负载。

以下是新 AsyncAPI v3 规范的示例:

asyncapi: 3.0.0
info:
  title: Example with Avro and GCP pubsub
  version: 0.1.0
channels:
  example:
    address: my-topic
    messages:
      myAvroMessage:
        payload:
          schemaFormat: application/vnd.apache.avro;version=1.9.0
          schema:
            type: record
            name: User
            namespace: com.company
            doc: User information
            fields:
              - name: displayName
                type: string
              - name: email
                type: string
              - name: age
                type: int
operations:
  example.publish:
    action: receive
    channel:
      $ref: '#/channels/example'
    messages:
      - $ref: '#/channels/example/messages/myAvroMessage'

还可以在工作室中查看 HTML 预览

如果您需要定义显式的 Google PubSub 信息,您可以使用称为 Bindings 的概念,它可以在通道、操作和消息上定义。

请在此处的 Studio 中查看。这只是一个简单的例子,上面有一个示例 Google PubSub 绑定信息。

asyncapi: 3.0.0
info:
  title: Example with Avro and GCP pubsub
  version: 0.1.0
channels:
  example:
    address: my-topic
    messages:
      myAvroMessage:
        payload:
          schemaFormat: application/vnd.apache.avro;version=1.9.0
          schema:
            type: record
            name: User
            namespace: com.company
            doc: User information
            fields:
              - name: displayName
                type: string
              - name: email
                type: string
              - name: age
                type: int
    bindings:
      googlepubsub:
        messageRetentionDuration: 86400s
        messageStoragePolicy:
          allowedPersistenceRegions:
          - us-central1
          - us-central2
          - us-east1
          - us-east4
          - us-east5
          - us-east7
          - us-south1
          - us-west1
          - us-west2
          - us-west3
          - us-west4
        schemaSettings:
          encoding: binary
          name: projects/your-project/schemas/message-proto
operations:
  example.publish:
    action: receive
    channel:
      $ref: '#/channels/example'
    messages:
      - $ref: '#/channels/example/messages/myAvroMessage'

在此处查看 Google pubsub 的所有文档和示例

© www.soinside.com 2019 - 2024. All rights reserved.