azqlite

package module
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 15, 2022 License: MIT Imports: 5 Imported by: 0

README

azqlite Go Reference

azqlite is a lightweight wrapper around github.com/Azure/azure-storage-queue-go to interact with the Azure Storage Queue service in a simpler and more idiomatic way.

Install

go get github.com/josebalius/azqlite

How to use

Instantiate a service
client, err := azqlite.NewClient(azqlite.Config{
	AccountName: "YOUR_AZURE_STORAGE_ACCOUNT_NAME_HERE",
	AccountKey:  "YOUR_AZURE_STORAGE_ACCOUNT_KEY_HERE",
})
Create a queue
q, err := client.CreateQueue(ctx, "test")
Delete a queue
err = c.DeleteQueue(ctx, "test")
Get an existing queue
q := c.GetQueue("test")
Get message count
c, err := q.MessageCount(ctx)
Enqueue a message
m, err := q.Enqueue(ctx, "my message", 1*time.Second, -time.Second)
Dequeue messages
messages, err := q.Dequeue(ctx, 30, 1*time.Second)
Peek messages
messages, err := q.Peek(ctx, 30)
Delete a message
err := q.Delete(ctx, &Message{ID: "1"})

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client added in v1.2.0

type Client struct {
	// contains filtered or unexported fields
}

Client represents a queue service.

func NewClient added in v1.2.0

func NewClient(cfg Config) (*Client, error)

NewClient creates a new Azure Queue Service. It is configured via the supplied Config. The config can contain a different AzureServiceURL to use for the service, this is useful for testing.

func (*Client) CreateQueue added in v1.2.0

func (c *Client) CreateQueue(ctx context.Context, queueName string) (Queue, error)

CreateQueue creates a new queue with the given name.

func (*Client) DeleteQueue added in v1.2.0

func (c *Client) DeleteQueue(ctx context.Context, queueName string) error

DeleteQueue deletes the queue with the given name.

func (*Client) GetQueue added in v1.2.0

func (c *Client) GetQueue(queueName string) Queue

GetQueue returns an existing queue with the given name.

type Config

type Config struct {
	AccountName string
	AccountKey  string

	// AzureServiceURL is optional to override the default Azure Service URL.
	AzureServiceURL string
}

Config is a set of configuration options for the Azure Queue Service.

type Message

type Message struct {
	ID           string
	PopReceipt   string
	DequeueCount int
	Body         string
}

type Queue

type Queue interface {
	// MessageCount returns an approximate number of messages in the queue.
	MessageCount(ctx context.Context) (int, error)

	// Enqueue adds a message to the queue. The timeout represents how long the message
	// should be hidden from consumers. The ttl is how long the message should be kept
	// in the queue. Pass -time.Second for infinite lifetime.
	Enqueue(ctx context.Context, message string, timeout, ttl time.Duration) (*Message, error)

	// Dequeue removes a message from the queue. The timeout represents how long the
	// message should be hidden from consumers. If the message is not deleted, it will
	// reappear in the queue after the timeout.
	Dequeue(ctx context.Context, count int, timeout time.Duration) ([]*Message, error)

	// Peek returns the next set of messages in the queue without removing it. The count
	// represents how many messages to return.
	Peek(ctx context.Context, count int) ([]*Message, error)

	// Delete removes the message from the queue.
	Delete(ctx context.Context, m *Message) error
}

Queue represents a queue in Azure Storage. It provides a core set of operations to interact with a queue.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL