mq

package module
v0.0.0-...-7a7206b Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2026 License: MIT Imports: 21 Imported by: 0

README

📨 mq — Unified Message Queue Module

godoc license Go Version codecov binary footprint

A unified Starlark module for message queue operations across AWS SQS and Azure Service Bus. It gives scripts one consistent surface for queue management, message send/receive, scheduling, lock management, and dead letter queue handling — without learning either vendor SDK.

Overview

  • One interface, two backends — the same client API drives AWS SQS and Azure Service Bus, with auto-detection from the supplied credentials.
  • Queue managementcreate_queue, delete_queue, list_queues, get_queue, exists, purge, get_info.
  • Message operationssend, receive, delete, batch_send, schedule, cancel, peek.
  • Lock & dead-letterlock / unlock, plus dead_letter_receive / dead_letter_requeue / dead_letter_purge.
  • Unified results & errors — both backends return the same Queue / MessageResult shapes and a normalized error taxonomy.

Where this fits. starpkg provides support for necessary local operations plus simple abstractions over common online services, for ease of use. mq is squarely in the online-service half: it wraps two managed cloud queue services behind one Starlark-friendly surface. It is an L4 domain module, depending downward on starpkg/base (the module/config system), 1set/starlet (the Machine runner + dataconv), and transitively 1set/starlight + go.starlark.net.

For the complete per-builtin / per-method reference — signatures, parameters, returns, errors, examples — and the configuration accessors, see docs/API.md.

Installation

go get github.com/starpkg/mq

Quick Start

load("mq", "connect")

def main():
    # Connect to your message queue service
    client = connect(
        service_type="azure_servicebus",
        connection_string="Endpoint=sb://..."
    )

    # Create a queue
    client.create_queue("orders")

    # Send a message
    result = client.send("orders", "New order received")
    print("Message sent: {}".format(result["message_id"]))

    # Receive and process messages
    messages = client.receive("orders", max_count=10)
    for msg in messages:
        print("Processing: {}".format(msg["body"]))
        # Process message here...
        client.delete("orders", msg["message_id"])

main()

Connect to AWS SQS, or let the module auto-detect from the credentials:

load("mq", "connect", "get_supported_services")

def main():
    print("Supported: {}".format(get_supported_services()))

    # AWS SQS
    aws_client = connect(
        service_type="aws_sqs",
        aws_region="us-west-2",
        aws_access_key="YOUR_ACCESS_KEY",
        aws_secret_key="YOUR_SECRET_KEY"
    )

    # Auto-detect (a connection string ⇒ Azure, otherwise AWS SQS)
    auto_client = connect(aws_region="us-east-1")  # Will use AWS SQS

main()

Starlark API at a glance

Module builtins (load("mq", …)):

  • connect(service_type?, connection_string?, aws_region?, aws_access_key?, aws_secret_key?, timeout?, max_retries?) — open a client (returns a client object).
  • get_supported_services() — list the supported services (["aws_sqs", "azure_servicebus"]).
  • get_client_info(client) — info dict for a client (same payload as the client method).

Client object methods (queue operations):

  • create_queue(name, lock_duration?, retention_period?, max_delivery_count?, dead_letter_config?, enable_sessions?, duplicate_detection?, duplicate_window_secs?, max_queue_size?) — create a queue.
  • delete_queue(name) — delete a queue.
  • list_queues(prefix?) — list queues (optionally by prefix).
  • get_queue(name) — queue info, or None.
  • exists(name) — whether a queue exists.
  • purge(name) — purge all messages from a queue.
  • get_info(name) — detailed queue statistics.

Client object methods (message operations):

  • send(queue_name, body, properties?, scheduled_time?, session_id?, correlation_id?, reply_to?, time_to_live?, message_id?) — send a message.
  • receive(queue_name, max_count?, wait_time?, lock_duration?, peek_only?) — receive messages.
  • delete(queue_name, message_ids) — delete by ID(s); returns a list of bools.
  • batch_send(queue_name, messages) — send a list of message dicts.
  • schedule(queue_name, body, scheduled_time, properties?, session_id?) — schedule a message.
  • cancel(queue_name, message_id) — cancel a scheduled message.
  • peek(queue_name, max_count?) — peek without receiving.

Client object methods (lock, dead letter, info):

  • lock(queue_name, message_id, lock_duration) — extend a message lock.
  • unlock(queue_name, message_id) — release a message lock.
  • dead_letter_receive(queue_name, max_count?) — receive from the DLQ.
  • dead_letter_requeue(queue_name, message_id) — move a message back to the main queue.
  • dead_letter_purge(queue_name) — purge the DLQ.
  • get_client_info() — info dict for the client.

Some operations are stubs or unsupported on one backend (e.g. AWS purge / lock / unlock / batch_send, Azure delete / cancel / peek). See the implementation status matrix in docs/API.md for the full signatures, return values, errors, and per-service behaviour of every builtin and method above.

Configuration

The module's options (service_type, timeout, max_retries, connection_string, aws_region, aws_access_key, aws_secret_key, aws_session_token, default_lock_duration, default_batch_size) are configured via environment variables (MQ_*) or per-option get_<key> / set_<key> accessor builtins, and serve as defaults for connect. Secret options (the connection string and AWS credentials) expose only set_<key> — never a getter. See the Configuration section of docs/API.md for the full option table, defaults, accessors, and secret rules.

License

This project is licensed under the MIT License — see the LICENSE file for details.

Documentation

Overview

Package mq provides a Starlark module for unified message queue operations. It supports AWS SQS and Azure Service Bus with a consistent API.

Index

Constants

View Source
const (
	ServiceTypeAWSSQS          = "aws_sqs"
	ServiceTypeAzureServiceBus = "azure_servicebus"
	ServiceTypeAuto            = "auto"
)

Service type constants

View Source
const ModuleName = "mq"

ModuleName defines the expected name for this module when used in Starlark's load() function

Variables

View Source
var (
	// ErrQueueNotFound indicates that the specified queue does not exist
	ErrQueueNotFound = errors.New("queue not found")

	// ErrQueueAlreadyExists indicates that the queue already exists
	ErrQueueAlreadyExists = errors.New("queue already exists")

	// ErrMessageNotFound indicates that the specified message does not exist
	ErrMessageNotFound = errors.New("message not found")

	// ErrMessageTooLarge indicates that the message exceeds size limits
	ErrMessageTooLarge = errors.New("message too large")

	// ErrAccessDenied indicates insufficient permissions
	ErrAccessDenied = errors.New("access denied")

	// ErrThrottled indicates that the request was throttled
	ErrThrottled = errors.New("request throttled")

	// ErrServiceUnavailable indicates that the service is temporarily unavailable
	ErrServiceUnavailable = errors.New("service unavailable")

	// ErrInvalidParameter indicates invalid parameter values
	ErrInvalidParameter = errors.New("invalid parameter")

	// ErrUnsupportedOperation indicates that the operation is not supported by the service
	ErrUnsupportedOperation = errors.New("unsupported operation")

	// ErrConnectionFailed indicates that connection to the service failed
	ErrConnectionFailed = errors.New("connection failed")

	// ErrTimeout indicates that the operation timed out
	ErrTimeout = errors.New("operation timed out")
)

Common error types for unified error handling across services

Functions

func IsRetryableError

func IsRetryableError(err error) bool

IsRetryableError determines if an error is retryable

func IsTemporaryError

func IsTemporaryError(err error) bool

IsTemporaryError determines if an error is temporary

func NormalizeError

func NormalizeError(service, operation string, err error) error

NormalizeError converts service-specific errors to unified MQError types

Types

type AWSSQSClient

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

AWSSQSClient implements the Client interface for AWS SQS

func (*AWSSQSClient) BatchSend

func (c *AWSSQSClient) BatchSend(ctx context.Context, queueName string, messages []BatchMessage) ([]*MessageResult, error)

BatchSend sends multiple messages in batches

func (*AWSSQSClient) Cancel

func (c *AWSSQSClient) Cancel(ctx context.Context, queueName, messageID string) error

Cancel cancels a scheduled message (not supported by SQS)

func (*AWSSQSClient) Close

func (c *AWSSQSClient) Close() error

Close closes the client connection

func (*AWSSQSClient) CreateQueue

func (c *AWSSQSClient) CreateQueue(ctx context.Context, name string, options QueueOptions) (*Queue, error)

CreateQueue creates a new SQS queue

func (*AWSSQSClient) DeadLetterPurge

func (c *AWSSQSClient) DeadLetterPurge(ctx context.Context, queueName string) error

DeadLetterPurge purges all messages from the dead letter queue

func (*AWSSQSClient) DeadLetterReceive

func (c *AWSSQSClient) DeadLetterReceive(ctx context.Context, queueName string, maxCount int) ([]*MessageResult, error)

DeadLetterReceive receives messages from the dead letter queue

func (*AWSSQSClient) DeadLetterRequeue

func (c *AWSSQSClient) DeadLetterRequeue(ctx context.Context, queueName, messageID string) error

DeadLetterRequeue moves a message back from DLQ to main queue

func (*AWSSQSClient) Delete

func (c *AWSSQSClient) Delete(ctx context.Context, queueName string, messageIDs []string) ([]bool, error)

Delete deletes messages from a queue

func (*AWSSQSClient) DeleteQueue

func (c *AWSSQSClient) DeleteQueue(ctx context.Context, name string) error

DeleteQueue deletes an SQS queue

func (*AWSSQSClient) Exists

func (c *AWSSQSClient) Exists(ctx context.Context, name string) (bool, error)

Exists checks if a queue exists

func (*AWSSQSClient) GetClientInfo

func (c *AWSSQSClient) GetClientInfo() map[string]interface{}

GetClientInfo returns information about the client

func (*AWSSQSClient) GetInfo

func (c *AWSSQSClient) GetInfo(ctx context.Context, name string) (*Queue, error)

GetInfo gets detailed queue information

func (*AWSSQSClient) GetQueue

func (c *AWSSQSClient) GetQueue(ctx context.Context, name string) (*Queue, error)

GetQueue gets information about a specific queue

func (*AWSSQSClient) ListQueues

func (c *AWSSQSClient) ListQueues(ctx context.Context, prefix string) ([]*Queue, error)

ListQueues lists SQS queues

func (*AWSSQSClient) Lock

func (c *AWSSQSClient) Lock(ctx context.Context, queueName, messageID string, duration int) error

Lock extends the visibility timeout of a message

func (*AWSSQSClient) Peek

func (c *AWSSQSClient) Peek(ctx context.Context, queueName string, maxCount int) ([]*MessageResult, error)

Peek peeks at messages without receiving them (not supported by SQS)

func (*AWSSQSClient) Purge

func (c *AWSSQSClient) Purge(ctx context.Context, name string) error

Purge purges all messages from a queue

func (*AWSSQSClient) Receive

func (c *AWSSQSClient) Receive(ctx context.Context, queueName string, options ReceiveOptions) ([]*MessageResult, error)

Receive receives messages from a queue

func (*AWSSQSClient) Schedule

func (c *AWSSQSClient) Schedule(ctx context.Context, queueName, body string, scheduledTime time.Time, options MessageOptions) (*MessageResult, error)

Schedule schedules a message for future delivery

func (*AWSSQSClient) Send

func (c *AWSSQSClient) Send(ctx context.Context, queueName, body string, options MessageOptions) (*MessageResult, error)

Send sends a message to a queue

func (*AWSSQSClient) Unlock

func (c *AWSSQSClient) Unlock(ctx context.Context, queueName, messageID string) error

Unlock releases a message by setting visibility timeout to 0

type AzureServiceBusClient

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

AzureServiceBusClient implements the Client interface for Azure Service Bus

func (*AzureServiceBusClient) AbandonMessage

func (c *AzureServiceBusClient) AbandonMessage(ctx context.Context, queueName string, msgResult *MessageResult) error

AbandonMessage abandons a message using the original Azure ReceivedMessage

func (*AzureServiceBusClient) BatchSend

func (c *AzureServiceBusClient) BatchSend(ctx context.Context, queueName string, messages []BatchMessage) ([]*MessageResult, error)

BatchSend sends multiple messages in batches

func (*AzureServiceBusClient) Cancel

func (c *AzureServiceBusClient) Cancel(ctx context.Context, queueName, messageID string) error

Cancel cancels a scheduled message

func (*AzureServiceBusClient) Close

func (c *AzureServiceBusClient) Close() error

Close closes the client connection

func (*AzureServiceBusClient) CompleteMessage

func (c *AzureServiceBusClient) CompleteMessage(ctx context.Context, queueName string, msgResult *MessageResult) error

CompleteMessage completes a message using the original Azure ReceivedMessage

func (*AzureServiceBusClient) CreateQueue

func (c *AzureServiceBusClient) CreateQueue(ctx context.Context, name string, options QueueOptions) (*Queue, error)

CreateQueue creates a new Service Bus queue using admin client

func (*AzureServiceBusClient) DeadLetterPurge

func (c *AzureServiceBusClient) DeadLetterPurge(ctx context.Context, queueName string) error

DeadLetterPurge purges all messages from the dead letter queue

func (*AzureServiceBusClient) DeadLetterReceive

func (c *AzureServiceBusClient) DeadLetterReceive(ctx context.Context, queueName string, maxCount int) ([]*MessageResult, error)

DeadLetterReceive receives messages from the dead letter queue

func (*AzureServiceBusClient) DeadLetterRequeue

func (c *AzureServiceBusClient) DeadLetterRequeue(ctx context.Context, queueName, messageID string) error

DeadLetterRequeue moves a message back from DLQ to main queue

func (*AzureServiceBusClient) Delete

func (c *AzureServiceBusClient) Delete(ctx context.Context, queueName string, messageIDs []string) ([]bool, error)

Delete deletes messages from a queue (completes them in Service Bus terms)

func (*AzureServiceBusClient) DeleteQueue

func (c *AzureServiceBusClient) DeleteQueue(ctx context.Context, name string) error

DeleteQueue deletes a Service Bus queue

func (*AzureServiceBusClient) Exists

func (c *AzureServiceBusClient) Exists(ctx context.Context, name string) (bool, error)

Exists checks if a queue exists

func (*AzureServiceBusClient) GetClientInfo

func (c *AzureServiceBusClient) GetClientInfo() map[string]interface{}

GetClientInfo returns information about the client

func (*AzureServiceBusClient) GetInfo

func (c *AzureServiceBusClient) GetInfo(ctx context.Context, name string) (*Queue, error)

GetInfo gets detailed queue information

func (*AzureServiceBusClient) GetQueue

func (c *AzureServiceBusClient) GetQueue(ctx context.Context, name string) (*Queue, error)

GetQueue gets information about a specific queue

func (*AzureServiceBusClient) ListQueues

func (c *AzureServiceBusClient) ListQueues(ctx context.Context, prefix string) ([]*Queue, error)

ListQueues lists Service Bus queues using admin client

func (*AzureServiceBusClient) Lock

func (c *AzureServiceBusClient) Lock(ctx context.Context, queueName, messageID string, duration int) error

Lock renews the lock on a message

func (*AzureServiceBusClient) Peek

func (c *AzureServiceBusClient) Peek(ctx context.Context, queueName string, maxCount int) ([]*MessageResult, error)

Peek peeks at messages without receiving them

func (*AzureServiceBusClient) Purge

func (c *AzureServiceBusClient) Purge(ctx context.Context, name string) error

Purge purges all messages from a queue

func (*AzureServiceBusClient) Receive

func (c *AzureServiceBusClient) Receive(ctx context.Context, queueName string, options ReceiveOptions) ([]*MessageResult, error)

Receive receives messages from a queue

func (*AzureServiceBusClient) RenewMessageLock

func (c *AzureServiceBusClient) RenewMessageLock(ctx context.Context, queueName string, msgResult *MessageResult) error

RenewMessageLock renews the lock on a message using the original Azure ReceivedMessage

func (*AzureServiceBusClient) Schedule

func (c *AzureServiceBusClient) Schedule(ctx context.Context, queueName, body string, scheduledTime time.Time, options MessageOptions) (*MessageResult, error)

Schedule schedules a message for future delivery

func (*AzureServiceBusClient) Send

func (c *AzureServiceBusClient) Send(ctx context.Context, queueName, body string, options MessageOptions) (*MessageResult, error)

Send sends a message to a queue

func (*AzureServiceBusClient) Unlock

func (c *AzureServiceBusClient) Unlock(ctx context.Context, queueName, messageID string) error

Unlock abandons a message (releases the lock)

type BatchMessage

type BatchMessage struct {
	Body          string                 // Message body
	Properties    map[string]interface{} // Message properties
	SessionID     string                 // Session ID
	CorrelationID string                 // Correlation ID
	ReplyTo       string                 // Reply to queue
	TimeToLive    int                    // TTL in seconds
	MessageID     string                 // Message ID
	ScheduledTime *time.Time             // Scheduled delivery time
}

BatchMessage represents a message for batch sending

type Client

type Client interface {
	// Queue operations
	CreateQueue(ctx context.Context, name string, options QueueOptions) (*Queue, error)
	DeleteQueue(ctx context.Context, name string) error
	ListQueues(ctx context.Context, prefix string) ([]*Queue, error)
	GetQueue(ctx context.Context, name string) (*Queue, error)
	Exists(ctx context.Context, name string) (bool, error)
	Purge(ctx context.Context, name string) error
	GetInfo(ctx context.Context, name string) (*Queue, error)

	// Message operations
	Send(ctx context.Context, queueName, body string, options MessageOptions) (*MessageResult, error)
	Receive(ctx context.Context, queueName string, options ReceiveOptions) ([]*MessageResult, error)
	Delete(ctx context.Context, queueName string, messageIDs []string) ([]bool, error)

	// Message lock management
	Lock(ctx context.Context, queueName, messageID string, duration int) error
	Unlock(ctx context.Context, queueName, messageID string) error

	// Batch operations
	BatchSend(ctx context.Context, queueName string, messages []BatchMessage) ([]*MessageResult, error)

	// Specialized message operations
	Schedule(ctx context.Context, queueName, body string, scheduledTime time.Time, options MessageOptions) (*MessageResult, error)
	Cancel(ctx context.Context, queueName, messageID string) error
	Peek(ctx context.Context, queueName string, maxCount int) ([]*MessageResult, error)

	// Dead letter queue operations
	DeadLetterReceive(ctx context.Context, queueName string, maxCount int) ([]*MessageResult, error)
	DeadLetterRequeue(ctx context.Context, queueName, messageID string) error
	DeadLetterPurge(ctx context.Context, queueName string) error

	// Connection management
	Close() error
	GetClientInfo() map[string]interface{}
}

Client interface defines the unified operations for message queue services

func NewAWSSQSClient

func NewAWSSQSClient(ctx context.Context, config *ClientConfig) (Client, error)

NewAWSSQSClient creates a new AWS SQS client

func NewAzureServiceBusClient

func NewAzureServiceBusClient(ctx context.Context, config *ClientConfig) (Client, error)

NewAzureServiceBusClient creates a new Azure Service Bus client

type ClientConfig

type ClientConfig struct {
	// Service configuration
	ServiceType      string // Service type (aws_sqs, azure_servicebus, auto)
	ConnectionString string // Azure Service Bus connection string

	// AWS specific configuration
	AWSRegion       string // AWS region
	AWSAccessKey    string // AWS access key ID
	AWSSecretKey    string // AWS secret access key
	AWSSessionToken string // AWS session token

	// Connection and performance settings
	Timeout    int // Connection timeout in seconds
	MaxRetries int // Maximum retry attempts

	// Default operation settings
	DefaultLockDuration int // Default message lock duration in seconds
	DefaultBatchSize    int // Default batch size for operations
}

ClientConfig contains configuration for a message queue client

func (*ClientConfig) Copy

func (c *ClientConfig) Copy() *ClientConfig

Copy creates a copy of the configuration

func (*ClientConfig) GetDefaultLockDuration

func (c *ClientConfig) GetDefaultLockDuration() time.Duration

GetDefaultLockDuration returns the default lock duration as a time.Duration

func (*ClientConfig) GetTimeout

func (c *ClientConfig) GetTimeout() time.Duration

GetTimeout returns the timeout as a time.Duration

func (*ClientConfig) Validate

func (c *ClientConfig) Validate() error

Validate validates the configuration

type ClientWrapper

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

ClientWrapper wraps the message queue client for Starlark

func NewClientWrapper

func NewClientWrapper(client Client) *ClientWrapper

NewClientWrapper creates a new ClientWrapper with initialized method maps.

Each method is registered with a literal qualified builtin name ("mq.<method>") passed directly to starlark.NewBuiltin. The runtime name is byte-identical to the historical "ModuleName + \".\" + name" form, but the literal lets the doccov documentation gate statically enumerate the object's script-facing surface.

func (*ClientWrapper) Attr

func (cw *ClientWrapper) Attr(name string) (starlark.Value, error)

Attr returns the named client method as a Starlark builtin, or a no-such-attr error.

func (*ClientWrapper) AttrNames

func (cw *ClientWrapper) AttrNames() []string

AttrNames returns the sorted-by-insertion list of client method names.

func (*ClientWrapper) Freeze

func (cw *ClientWrapper) Freeze()

Freeze is a no-op; the client is immutable after creation (required by the Starlark interface).

func (*ClientWrapper) Hash

func (cw *ClientWrapper) Hash() (uint32, error)

Hash reports the client as unhashable, since it wraps live network state.

func (*ClientWrapper) String

func (cw *ClientWrapper) String() string

String returns a human-readable representation of the wrapped client.

func (*ClientWrapper) Truth

func (cw *ClientWrapper) Truth() starlark.Bool

Truth reports the client as always truthy (required by the Starlark interface).

func (*ClientWrapper) Type

func (cw *ClientWrapper) Type() string

Type returns the Starlark type name of the client object.

type DeadLetterConfig

type DeadLetterConfig struct {
	Enabled          bool   // Whether DLQ is enabled
	QueueName        string // Dead letter queue name
	MaxDeliveryCount int    // Maximum delivery count before moving to DLQ
}

DeadLetterConfig contains dead letter queue configuration

type DuplicateDetection

type DuplicateDetection struct {
	Enabled       bool `json:"enabled"`
	WindowSeconds int  `json:"window_seconds"` // Deduplication window in seconds
}

DuplicateDetection represents duplicate detection configuration

type ErrorType

type ErrorType string

ErrorType categorizes different types of errors

const (
	// ErrorTypeNotFound indicates a queue or message was not found.
	ErrorTypeNotFound ErrorType = "not_found"
	// ErrorTypeAlreadyExists indicates a queue already exists.
	ErrorTypeAlreadyExists ErrorType = "already_exists"
	// ErrorTypePermission indicates the request was denied for lack of permission.
	ErrorTypePermission ErrorType = "permission"
	// ErrorTypeThrottling indicates the request was throttled or the service was busy.
	ErrorTypeThrottling ErrorType = "throttling"
	// ErrorTypeValidation indicates an invalid parameter or an over-large message.
	ErrorTypeValidation ErrorType = "validation"
	// ErrorTypeConnection indicates a connection to the service failed.
	ErrorTypeConnection ErrorType = "connection"
	// ErrorTypeTimeout indicates the operation timed out.
	ErrorTypeTimeout ErrorType = "timeout"
	// ErrorTypeService indicates a transient service-side failure or unavailability.
	ErrorTypeService ErrorType = "service"
	// ErrorTypeUnsupported indicates the operation is not supported by the service.
	ErrorTypeUnsupported ErrorType = "unsupported"
	// ErrorTypeUnknown indicates an error that did not match any known category.
	ErrorTypeUnknown ErrorType = "unknown"
)

The ErrorType values categorize a normalized MQError independently of the backing service, so scripts and callers can branch on a stable taxonomy.

type MQError

type MQError struct {
	// Type categorizes the error
	Type ErrorType

	// Message provides a human-readable description
	Message string

	// Service indicates which service reported the error
	Service string

	// Operation indicates which operation failed
	Operation string

	// Underlying error from the service
	Err error

	// Additional context
	Context map[string]interface{}
}

MQError represents a message queue operation error with additional context

func NewMQError

func NewMQError(errType ErrorType, service, operation, message string, err error) *MQError

NewMQError creates a new MQError

func (*MQError) Error

func (e *MQError) Error() string

Error implements the error interface

func (*MQError) Is

func (e *MQError) Is(target error) bool

Is checks if the error matches a target error

func (*MQError) Unwrap

func (e *MQError) Unwrap() error

Unwrap returns the underlying error

func (*MQError) WithContext

func (e *MQError) WithContext(key string, value interface{}) *MQError

WithContext adds context to the error

type MessageOptions

type MessageOptions struct {
	// Message properties and metadata
	Properties map[string]interface{} // Message properties/attributes

	// Message scheduling
	ScheduledTime *time.Time // When message should become available for processing

	// Message grouping and correlation
	SessionID     string // Session ID for ordered processing
	CorrelationID string // Correlation ID for request tracking
	ReplyTo       string // Response destination queue

	// Message lifecycle
	TimeToLive int    // Message TTL in seconds
	MessageID  string // Message ID for deduplication
}

MessageOptions contains options for sending messages

type MessageResult

type MessageResult struct {
	// Message identification
	MessageID string `json:"message_id"`
	Body      string `json:"body"`

	// Message metadata and properties
	Properties map[string]interface{} `json:"properties"`

	// Message grouping and correlation
	SessionID     string `json:"session_id"`
	CorrelationID string `json:"correlation_id"`
	ReplyTo       string `json:"reply_to"`

	// Timing information
	EnqueueTime   time.Time  `json:"enqueue_time"`
	ScheduledTime *time.Time `json:"scheduled_time,omitempty"`
	LockExpiresAt *time.Time `json:"lock_expires_at,omitempty"`

	// Delivery information
	DeliveryCount int `json:"delivery_count"`
	TimeToLive    int `json:"time_to_live"` // TTL in seconds

	// Service-specific information (internal use)
	ReceiptHandle   string      `json:"receipt_handle"` // Service-specific handle for acknowledgment
	OriginalMessage interface{} `json:"-"`              // Original service-specific message object (not serialized)

	// Operation result
	Success bool   `json:"success"`
	Error   string `json:"error,omitempty"`
}

MessageResult represents a message received from or sent to a queue

func NewMessageResult

func NewMessageResult(messageID, body string) *MessageResult

NewMessageResult creates a new MessageResult with basic information

func (*MessageResult) IsExpired

func (m *MessageResult) IsExpired() bool

IsExpired checks if the message lock has expired

func (*MessageResult) IsScheduled

func (m *MessageResult) IsScheduled() bool

IsScheduled checks if the message is scheduled for future delivery

func (*MessageResult) Struct

func (m *MessageResult) Struct() (starlark.Value, error)

Struct converts MessageResult to a Starlark dict value for compatibility

func (*MessageResult) TimeUntilExpiry

func (m *MessageResult) TimeUntilExpiry() time.Duration

TimeUntilExpiry returns the duration until the message lock expires

func (*MessageResult) TimeUntilScheduled

func (m *MessageResult) TimeUntilScheduled() time.Duration

TimeUntilScheduled returns the duration until the message becomes available

type Module

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

Module wraps the ConfigurableModule with specific functionality for MQ operations

func NewModule

func NewModule() *Module

NewModule creates a new instance of Module with default configurations

func (*Module) LoadModule

func (m *Module) LoadModule() starlet.ModuleLoader

LoadModule returns the Starlark module loader with MQ-specific functions

type Queue

type Queue struct {
	// Basic queue information
	Name        string `json:"name"`
	ServiceType string `json:"service_type"` // Which service backs this queue
	URL         string `json:"url"`          // Service-specific queue URL/identifier

	// Queue statistics
	MessageCount int `json:"message_count"`

	// Queue configuration (unified across services)
	LockDuration    int `json:"lock_duration"`    // Message lock duration in seconds
	RetentionPeriod int `json:"retention_period"` // Message retention in seconds

	// Dead letter queue configuration
	MaxDeliveryCount int               `json:"max_delivery_count"`
	DeadLetterConfig *DeadLetterConfig `json:"dead_letter_config"`

	// Message ordering and deduplication
	EnableSessions     bool                `json:"enable_sessions"`     // Ordered processing support
	DuplicateDetection *DuplicateDetection `json:"duplicate_detection"` // Deduplication configuration

	// Queue limits
	MaxQueueSize int64 `json:"max_queue_size"` // Queue size in bytes (-1 for unlimited)

	// Timestamps
	CreatedTime  time.Time `json:"created_time"`
	ModifiedTime time.Time `json:"modified_time"`
}

Queue represents a message queue with unified properties across services

func NewQueue

func NewQueue(name, serviceType string) *Queue

NewQueue creates a new Queue with default values

func (*Queue) Copy

func (q *Queue) Copy() *Queue

Copy creates a copy of the Queue

func (*Queue) FromStarlark

func (q *Queue) FromStarlark(val starlark.Value) error

FromStarlark populates Queue from a Starlark value

func (*Queue) GetLockDuration

func (q *Queue) GetLockDuration() time.Duration

GetLockDuration returns the lock duration as a time.Duration

func (*Queue) GetRetentionPeriod

func (q *Queue) GetRetentionPeriod() time.Duration

GetRetentionPeriod returns the retention period as a time.Duration

func (*Queue) IsDeadLetterEnabled

func (q *Queue) IsDeadLetterEnabled() bool

IsDeadLetterEnabled checks if dead letter queue is enabled

func (*Queue) IsDuplicateDetectionEnabled

func (q *Queue) IsDuplicateDetectionEnabled() bool

IsDuplicateDetectionEnabled checks if duplicate detection is enabled

func (*Queue) Struct

func (q *Queue) Struct() (starlark.Value, error)

Struct converts Queue to a Starlark dict value for compatibility

type QueueOptions

type QueueOptions struct {
	// Lock duration for messages (unified visibility timeout/lock duration)
	LockDuration int // Message lock duration in seconds

	// Message retention settings
	RetentionPeriod int // Message retention period in seconds

	// Dead letter queue configuration
	MaxDeliveryCount int               // Maximum delivery attempts before moving to DLQ
	DeadLetterConfig *DeadLetterConfig // Dead letter queue configuration

	// Message ordering and deduplication
	EnableSessions      bool // Enable sessions for message ordering (Azure) or FIFO (AWS)
	DuplicateDetection  bool // Enable duplicate message detection
	DuplicateWindowSecs int  // Duplicate detection window in seconds

	// Queue size limits
	MaxQueueSize int64 // Maximum queue size in bytes (-1 for unlimited)
}

QueueOptions contains options for creating or configuring a queue

type ReceiveOptions

type ReceiveOptions struct {
	// Receive behavior
	MaxCount int  // Maximum number of messages to receive
	WaitTime int  // Long polling wait time in seconds
	PeekOnly bool // Peek messages without receiving them

	// Message lock settings
	LockDuration *int // Override default lock duration
}

ReceiveOptions contains options for receiving messages

Jump to

Keyboard shortcuts

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