Skip to content

AMQP

AMQP binding。輸出的成員是 amqp,每個物件都帶 bindingVersion: 0.3.0

@amqpChannel

typespec
extern dec amqpChannel(
  target: Interface | Namespace,
  config: valueof AsyncAPIAmqpChannelBinding
);
欄位型別必填
isstring
exchangeAsyncAPIAmqpExchange
queueAsyncAPIAmqpQueue

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

WARNING

is 是 TypeSpec 的關鍵字。欄位名稱要用反引號寫成 `is`: "routingKey"。輸出的成員仍然是 is

isqueueroutingKeyexchange.typetopicdirectfanoutdefaultheaders 其中之一。exchange 或 queue 的名稱最長 255 個字元。

這個成員涵蓋 AMQP 0-9-1。AsyncAPI 另外定義 amqp1 給 AMQP 1.0,本 library 不輸出它。

typespec
@amqpChannel(#{
  `is`: "routingKey",
  exchange: #{ name: "events", type: "topic", durable: true }
})
@channel("events.created")
interface EventChannel {}
yaml
channels:
  events.created:
    address: events.created
    bindings:
      amqp:
        is: routingKey
        exchange:
          name: events
          type: topic
          durable: true
        bindingVersion: 0.3.0

@amqpOperation

typespec
extern dec amqpOperation(target: Operation, config: valueof AsyncAPIAmqpOperationBinding);
欄位型別必填
expirationint32
userIdstring
ccstring[]
priorityint32
deliveryModeint32
mandatoryboolean
bccstring[]
timestampboolean
ackboolean

套用在帶有 @send@receive 的 operation 上。

deliveryMode1 表示暫存,2 表示持久化。expiration 是毫秒數,是零或以上。

輸出的欄位順序依照規格,不是作者書寫的順序。

typespec
@send
@amqpOperation(#{ deliveryMode: 2, expiration: 60000, mandatory: true })
op publish(event: EventCreated): void;
yaml
operations:
  publish:
    action: send
    channel:
      $ref: "#/channels/events.created"
    bindings:
      amqp:
        expiration: 60000
        deliveryMode: 2
        mandatory: true
        bindingVersion: 0.3.0

@amqpMessage

typespec
extern dec amqpMessage(target: Model, config: valueof AsyncAPIAmqpMessageBinding);
欄位型別必填
contentEncodingstring
messageTypestring

套用在同時帶有 @message 的 model 上。AMQP 對這兩個欄位都沒有規定值的集合。

typespec
@message
@amqpMessage(#{ contentEncoding: "gzip", messageType: "event.created" })
model EventCreated {
  eventId: string;
}
yaml
components:
  messages:
    EventCreated:
      name: EventCreated
      payload:
        $ref: "#/components/schemas/EventCreated"
      bindings:
        amqp:
          contentEncoding: gzip
          messageType: event.created
          bindingVersion: 0.3.0