Skip to content

Google Cloud Pub/Sub

Google Cloud Pub/Sub binding。輸出的成員是 googlepubsub,每個物件都帶 bindingVersion: 0.2.0

@googlePubSubChannel

typespec
extern dec googlePubSubChannel(
  target: Interface | Namespace,
  config: valueof AsyncAPIGooglePubSubChannelBinding
);
欄位型別必填
schemaSettingsAsyncAPIGooglePubSubSchemaSettings
labelsRecord<unknown>
messageRetentionDurationstring
messageStoragePolicyAsyncAPIGooglePubSubStoragePolicy

套用在帶有 @channel@dynamicChannel 的 interface 或 namespace 上。

schemaSettings 是必填,它自己又要求 encodingname。缺這些時,binding 會透過 missing-binding-field 回報並整個丟棄。

labels 是開放的 map。Pub/Sub 對它的鍵與值都沒有規定,所以原樣輸出。

typespec
@googlePubSubChannel(#{
  schemaSettings: #{ encoding: "json", name: "projects/p/schemas/order" },
  messageRetentionDuration: "604800s",
  labels: #{ team: "orders" }
})
@channel("projects/p/topics/orders")
interface OrderChannel {}
yaml
channels:
  projects/p/topics/orders:
    address: projects/p/topics/orders
    bindings:
      googlepubsub:
        schemaSettings:
          encoding: json
          name: projects/p/schemas/order
        labels:
          team: orders
        messageRetentionDuration: 604800s
        bindingVersion: 0.2.0

@googlePubSubMessage

typespec
extern dec googlePubSubMessage(
  target: Model,
  config: valueof AsyncAPIGooglePubSubMessageBinding
);
欄位型別必填
attributesRecord<unknown>
orderingKeystring
schemaAsyncAPIGooglePubSubSchema

套用在同時帶有 @message 的 model 上。

schema 是選填,但寫了 schema 卻沒寫 name 等於沒指名任何 schema。這時 binding 會透過 missing-binding-field 回報並整個丟棄。

typespec
@message
@googlePubSubMessage(#{
  orderingKey: "tenantId",
  attributes: #{ region: "asia-east1" },
  schema: #{ name: "projects/p/schemas/order" }
})
model OrderCreated {
  orderId: string;
}
yaml
components:
  messages:
    OrderCreated:
      name: OrderCreated
      payload:
        $ref: "#/components/schemas/OrderCreated"
      bindings:
        googlepubsub:
          attributes:
            region: asia-east1
          orderingKey: tenantId
          schema:
            name: projects/p/schemas/order
          bindingVersion: 0.2.0