or run

tessl search
Log in

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
golangpkg:golang/github.com/Azure/azure-sdk-for-go/sdk/storage/azqueue/v2@v2.0.1
tile.json

tessl/golang-github-com-azure-azure-sdk-for-go-sdk-storage-azqueue-v2

tessl install tessl/golang-github-com-azure-azure-sdk-for-go-sdk-storage-azqueue-v2@2.0.1

Azure Queue Storage SDK for Go provides comprehensive client library for interacting with Azure's cloud-based message queue service including queue management, message operations, and multiple authentication methods.

index.mddocs/

Azure Queue Storage SDK for Go (azqueue)

Azure Queue Storage SDK for Go provides comprehensive client library for interacting with Azure's cloud-based message queue service. It enables applications to store and access messages up to 64 KiB in size, with queues containing millions of messages within storage account capacity limits. The SDK supports multiple authentication methods, goroutine-safe operations, and full queue and message lifecycle management.

Package Information

  • Package Name: azqueue
  • Package Type: golang
  • Language: Go
  • Module Path: github.com/Azure/azure-sdk-for-go/sdk/storage/azqueue/v2
  • Installation: go get github.com/Azure/azure-sdk-for-go/sdk/storage/azqueue/v2
  • Documentation: https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/storage/azqueue/v2

Core Imports

import (
    "github.com/Azure/azure-sdk-for-go/sdk/storage/azqueue/v2"
    "github.com/Azure/azure-sdk-for-go/sdk/storage/azqueue/v2/sas"
    "github.com/Azure/azure-sdk-for-go/sdk/storage/azqueue/v2/queueerror"
)

Basic Usage

import (
    "context"
    "fmt"
    "github.com/Azure/azure-sdk-for-go/sdk/azidentity"
    "github.com/Azure/azure-sdk-for-go/sdk/storage/azqueue/v2"
)

func main() {
    // Authenticate with Azure AD
    cred, err := azidentity.NewDefaultAzureCredential(nil)
    if err != nil {
        // handle error
    }

    // Create service client
    serviceClient, err := azqueue.NewServiceClient(
        "https://<account>.queue.core.windows.net/",
        cred,
        nil,
    )
    if err != nil {
        // handle error
    }

    // Create queue client
    queueClient := serviceClient.NewQueueClient("myqueue")

    // Create queue
    _, err = queueClient.Create(context.TODO(), nil)
    if err != nil {
        // handle error
    }

    // Enqueue message
    _, err = queueClient.EnqueueMessage(
        context.TODO(),
        "Hello, Queue!",
        nil,
    )
    if err != nil {
        // handle error
    }

    // Dequeue message
    resp, err := queueClient.DequeueMessage(context.TODO(), nil)
    if err != nil {
        // handle error
    }

    if len(resp.Messages) > 0 {
        msg := resp.Messages[0]
        fmt.Println(*msg.MessageText)

        // Delete message after processing
        _, err = queueClient.DeleteMessage(
            context.TODO(),
            *msg.MessageID,
            *msg.PopReceipt,
            nil,
        )
    }
}

Architecture

The azqueue SDK is organized around several key components:

  • ServiceClient: Account-level operations including queue management (create, delete, list), service properties configuration (CORS, logging, metrics), and geo-replication statistics
  • QueueClient: Queue-level operations including message lifecycle (enqueue, dequeue, peek, update, delete, clear), queue properties, metadata, and access policies
  • Authentication: Multiple credential types supporting Azure AD (TokenCredential), Shared Key (SharedKeyCredential), connection strings, and anonymous/SAS access
  • SAS Support: Account-level and queue-level Shared Access Signature generation with configurable permissions, time ranges, IP restrictions, and protocols
  • Error Handling: Comprehensive error code constants with helper functions for error matching and typed error responses
  • Goroutine Safety: All client methods are goroutine-safe and designed for concurrent use

Capabilities

Service Client Operations

Account-level operations for managing queues, configuring service properties, and accessing service statistics.

type ServiceClient struct { /* ... */ }

// Create service client with Azure AD credential
func NewServiceClient(serviceURL string, cred azcore.TokenCredential, options *ClientOptions) (*ServiceClient, error)

// Create service client with shared key credential
func NewServiceClientWithSharedKeyCredential(serviceURL string, cred *SharedKeyCredential, options *ClientOptions) (*ServiceClient, error)

// Create service client from connection string
func NewServiceClientFromConnectionString(connectionString string, options *ClientOptions) (*ServiceClient, error)

// Create service client for anonymous/SAS access
func NewServiceClientWithNoCredential(serviceURL string, options *ClientOptions) (*ServiceClient, error)

Service Client

Queue Client Operations

Queue-level operations for message lifecycle management, queue configuration, and access control.

type QueueClient struct { /* ... */ }

// Create queue client with Azure AD credential
func NewQueueClient(queueURL string, cred azcore.TokenCredential, options *ClientOptions) (*QueueClient, error)

// Create queue client with shared key credential
func NewQueueClientWithSharedKeyCredential(queueURL string, cred *SharedKeyCredential, options *ClientOptions) (*QueueClient, error)

// Create queue client from connection string
func NewQueueClientFromConnectionString(connectionString string, queueName string, options *ClientOptions) (*QueueClient, error)

// Create queue client for anonymous/SAS access
func NewQueueClientWithNoCredential(queueURL string, options *ClientOptions) (*QueueClient, error)

Queue Client

Shared Access Signatures (SAS)

Generate account-level and queue-level SAS tokens with customizable permissions, time ranges, and access restrictions.

// Account-level SAS
type AccountSignatureValues struct {
    Version       string
    Protocol      Protocol
    StartTime     time.Time
    ExpiryTime    time.Time
    Permissions   string
    IPRange       IPRange
    ResourceTypes string
}

func (v AccountSignatureValues) SignWithSharedKey(sharedKeyCredential *SharedKeyCredential) (QueryParameters, error)

// Queue-level SAS
type QueueSignatureValues struct {
    Version            string
    Protocol           Protocol
    StartTime          time.Time
    ExpiryTime         time.Time
    Permissions        string
    IPRange            IPRange
    Identifier         string
    QueueName          string
    // ... additional fields
}

func (v QueueSignatureValues) SignWithSharedKey(sharedKeyCredential *SharedKeyCredential) (QueryParameters, error)
func (v QueueSignatureValues) SignWithUserDelegation(userDelegationCredential *UserDelegationCredential) (QueryParameters, error)

SAS Token Generation

Error Handling

Comprehensive error code constants and helper functions for identifying and handling specific queue storage errors.

// Check if error matches specific error codes
func HasCode(err error, codes ...Code) bool

// Error code type
type Code = generated.StorageErrorCode

// Example error codes
const (
    QueueNotFound        Code = "QueueNotFound"
    QueueAlreadyExists   Code = "QueueAlreadyExists"
    QueueBeingDeleted    Code = "QueueBeingDeleted"
    MessageNotFound      Code = "MessageNotFound"
    MessageTooLarge      Code = "MessageTooLarge"
    // ... 50+ more error codes
)

Error Handling

Credential Types

SharedKeyCredential

Account credentials for shared key authentication.

type SharedKeyCredential = exported.SharedKeyCredential

// Create shared key credential
func NewSharedKeyCredential(accountName, accountKey string) (*SharedKeyCredential, error)

Usage:

cred, err := azqueue.NewSharedKeyCredential("myaccount", "mykey")
if err != nil {
    // handle error
}

serviceClient, err := azqueue.NewServiceClientWithSharedKeyCredential(
    "https://myaccount.queue.core.windows.net/",
    cred,
    nil,
)

Client Configuration

ClientOptions

Configuration options for client creation.

type ClientOptions = base.ClientOptions

ClientOptions allows customization of HTTP client behavior, retry policies, logging, and telemetry. Pass nil to accept default values.

Common Types

Queue

Represents a queue item returned from list operations.

type Queue = generated.Queue

Queue objects contain queue name, metadata, and are returned by ServiceClient.NewListQueuesPager.

Service Properties and Statistics

Types for service configuration and geo-replication statistics.

// Storage service properties
type StorageServiceProperties = generated.StorageServiceProperties

// Storage service statistics
type StorageServiceStats = generated.StorageServiceStats

// CORS rule for cross-domain access
type CORSRule = generated.CORSRule

// Metrics configuration
type Metrics = generated.Metrics

// Logging configuration
type Logging = generated.Logging

// Retention policy
type RetentionPolicy = generated.RetentionPolicy

// Geo-replication information
type GeoReplication = generated.GeoReplication

These types are used with ServiceClient.GetServiceProperties, ServiceClient.SetProperties, and ServiceClient.GetStatistics.

Access Control Types

Types for managing queue access policies.

// Signed identifier for access policies
type SignedIdentifier = generated.SignedIdentifier

// Access policy definition
type AccessPolicy = generated.AccessPolicy

// Access policy permission builder
type AccessPolicyPermission = exported.AccessPolicyPermission

URL Parsing

Parse queue URLs into components including SAS parameters.

// Parse URL into components
func ParseURL(u string) (URLParts, error)

// URL components
type URLParts struct {
    Scheme              string
    Host                string
    IPEndpointStyleInfo IPEndpointStyleInfo
    QueueName           string
    SAS                 QueryParameters
    UnparsedParams      string
}

// Reconstruct URL from parts
func (up URLParts) String() string

Thread Safety

All client instance methods are goroutine-safe and independent of each other. Client instances can be safely reused across multiple goroutines, which is the recommended practice for optimal resource usage.