tessl install tessl/golang-github-com-azure-azure-sdk-for-go-sdk-storage-azqueue-v2@2.0.1Azure 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.
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.
github.com/Azure/azure-sdk-for-go/sdk/storage/azqueue/v2go get github.com/Azure/azure-sdk-for-go/sdk/storage/azqueue/v2import (
"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"
)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,
)
}
}The azqueue SDK is organized around several key components:
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)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)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)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
)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,
)Configuration options for client creation.
type ClientOptions = base.ClientOptionsClientOptions allows customization of HTTP client behavior, retry policies, logging, and telemetry. Pass nil to accept default values.
Represents a queue item returned from list operations.
type Queue = generated.QueueQueue objects contain queue name, metadata, and are returned by ServiceClient.NewListQueuesPager.
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.GeoReplicationThese types are used with ServiceClient.GetServiceProperties, ServiceClient.SetProperties, and ServiceClient.GetStatistics.
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.AccessPolicyPermissionParse 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() stringAll 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.