Is there a way to document AVRO schema for GCP pubsub

130 views Asked by At

enter image description hereLike openAPI is there a way to document AVRO schema for GCP pubsub. Is there an UI provided by GCP like swagger UI. Or what is the recomendation here.

According to me Async API could be an option. But really not sure what is the best solution

1

There are 1 answers

0
jonaslagoni On

You can definitely use AsyncAPI for it as it's protocol agnostic, ontop of enabling you to define payloads with Avro.

Here is an example with the new AsyncAPI v3 specification:

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'

Also check it out in studio for a HTML preview.

If you need to define explicit Google PubSub information, you use the concept called Bindings, that can be defined on channels, operations and messages.

Check it out in Studio here. Here is just a simple example with the example above with an example Google PubSub binding information.

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'

Checkout all the documentation and examples for Google pubsub here.