Skip to content

Instantly share code, notes, and snippets.

@jsquire
Created April 5, 2024 19:42
Show Gist options
  • Save jsquire/539d1d4341b86eff276be984667f500a to your computer and use it in GitHub Desktop.
Save jsquire/539d1d4341b86eff276be984667f500a to your computer and use it in GitHub Desktop.
Example: Service Bus AMQP operations

Connections

Create connection

  • Use AMQP version 1.0.0.0

  • Use SASL with "MSSBCBS" as the mechanism name

  • Authorize via CBS to a dedicated link named "$cbs"

  • Add telemetry properties to connection:

    • product
    • version
    • framework
    • platform
    • user-agent
  • Sessions for this connection have no custom fields

  • For WebSockets

    • Use "/$servicebus/websocket/" as the connection path
    • Use standard HTTP ports
    • Use scheme "wss"

Create receiving link

  • Authorize via CBS link using claim "Listen" and Audience of the fully qualified endpoint

  • Settle mode:

    • Should be 2 (SettleOnDispose) for PeekLock
    • Should be 0 (SettleOnSend) for ReceiveAndDelete

Create sending link

  • Authorize via CBS link using claims "Send", "Listen", and "Manage" with an Audience of the fully qualified endpoint

  • Maximum message size is set on the link when opened via the standard "max-message-size" field in the Attach frame.

Create management link

Service operations

Peek message

  • Use a management link

  • Create an AMQP message with: Application properties:

    • "associated-link-name", value of type string; the name of the paired receiving link
    • "operation", value of type string; "com.microsoft.peek-message"
    • "com.microsoft:server-timeout"; type of uint; the server timeout in milliseconds

    Value body with a map containing:

    • "from-sequence-number", value of type Int64; the sequence number to start peeking from
    • "message-count", value of type Int32; the desired count of messages
  • The response link returns an AMQP message with the following:

    Application properties:

    • "statusCode", value of type Int32; 200 (OK) or 204 (No more messages)
    • "statusDescription"; value of type string; text description of the status

    Value body with a map containing:

    • "messages"; type of list; each map in the list represents a message

Renew message lock

  • Use a management link

  • Create an AMQP message with: Application properties:

    • "associated-link-name", value of type string; the name of the paired receiving link
    • "operation", value of type string; "com.microsoft:renew-lock"
    • "com.microsoft:server-timeout"; type of uint; the server timeout in milliseconds

    Value body with a map containing:

    • "lock-tokens", value of type array; the lock tokens to renew
  • The response link returns an AMQP message with the following:

    Application properties:

    • "statusCode", value of type Int32; HTTP response code
    • "statusDescription"; value of type string; text description of the status

    Value body with a map containing:

    • "expirations"; type of array; new expiration time for each message
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment