inssqs

package
v0.10.5 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

README

inssqs - AWS SQS Package

The inssqs package provides an interface and implementation for interacting with Amazon Simple Queue Service (SQS) in Go. It simplifies sending and deleting messages in batches while handling retries, respecting batch size constraints, and supporting concurrent operations.

Features

  • Batch Operations: Send and delete messages in batches to SQS queues.
  • Retries: Automatic retries for failed operations based on a configurable retry count.
  • Concurrency: Concurrent processing of multiple batches with specified worker count.
  • Error Handling: Detailed error logging and handling for failed operations.

Installation

To use this package in your Go project, import it as follows:

import "github.com/useinsider/go-pkg/inssqs"

Usage

Initialization

Initialize an SQS queue instance by providing configuration settings using NewSQS()

config := inssqs.Config{
    Region:            "your-aws-region",
    QueueName:         "your-queue-name",
    RetryCount:        3,
    MaxBatchSize:      10,
    MaxBatchSizeBytes: 1024,
    MaxWorkers:        5,
    LogLevel:          "info",
}

sqs := inssqs.NewSQS(config)
Sending Messages

Send a batch of messages to an SQS queue using SendMessageBatch()

messages := []inssqs.SQSMessageEntry{
    // Create SQS message entries here
}

failedMessages, err := sqs.SendMessageBatch(messages)
if err != nil {
    // Handle error
}
Deleting Messages

Delete a batch of messages from an SQS queue using DeleteMessageBatch()

messages := []inssqs.SQSDeleteMessageEntry{
    // Create SQS message entries here
}

failedMessages, err := sqs.DeleteMessageBatch(messages)
if err != nil {
    // Handle error
}

Configuration Options

  • Region: AWS region where the SQS queue resides.
  • QueueName: Name of the SQS queue.
  • RetryCount: Number of retry attempts allowed for queue operations.
  • MaxBatchSize: Maximum size of a message batch.
  • MaxBatchSizeBytes: Maximum size of a message batch in bytes.
  • MaxWorkers: Maximum number of workers for concurrent operations.
  • LogLevel: Log level for SQS operations. For more details on each function and its parameters, refer to the code documentation.

Contribution

Feel free to contribute by forking this repository and creating pull requests. Please ensure to adhere to the existing code style and conventions.

Documentation

Overview

Code generated by MockGen. DO NOT EDIT. Source: inssqs.go

Generated by this command:

mockgen --source=inssqs.go

Package mock_inssqs is a generated GoMock package.

Index

Constants

This section is empty.

Variables

View Source
var ErrQueueNameNotSet = errors.New("queue name not set")
View Source
var ErrRegionNotSet = errors.New("region not set")
View Source
var ErrRetryCountExceeded = errors.New("retry count exceeded")

Functions

This section is empty.

Types

type Config

type Config struct {
	Region            string // AWS region where the SQS queue resides.
	QueueName         string // Name of the SQS queue.
	RetryCount        int    // Number of retry attempts allowed for queue operations.
	MaxBatchSize      int    // Maximum size of a message batch.
	MaxBatchSizeBytes int    // Maximum size of a message batch in bytes.
	MaxWorkers        int    // Maximum number of workers for concurrent operations.
	LogLevel          string // Log level for SQS operations.

	EndpointUrl string // Endpoint URL for AWS operations.
}

Config represents the configuration settings required for initializing an SQS queue.

type FakeQueue

type FakeQueue struct {
	Interface
	Data []SQSMessageEntry
}

func (*FakeQueue) DeleteMessageBatch

func (q *FakeQueue) DeleteMessageBatch(entries []SQSDeleteMessageEntry) (failed []SQSDeleteMessageEntry, err error)

func (*FakeQueue) SendMessageBatch

func (q *FakeQueue) SendMessageBatch(entries []SQSMessageEntry) (failed []SQSMessageEntry, err error)

type Interface

type Interface interface {
	SendMessageBatch(entries []SQSMessageEntry) (failed []SQSMessageEntry, err error)
	DeleteMessageBatch(entries []SQSDeleteMessageEntry) (failed []SQSDeleteMessageEntry, err error)
}

func NewSQS

func NewSQS(config Config) Interface

type MockInterface

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

MockInterface is a mock of Interface interface.

func NewMockInterface

func NewMockInterface(ctrl *gomock.Controller) *MockInterface

NewMockInterface creates a new mock instance.

func (*MockInterface) DeleteMessageBatch

func (m *MockInterface) DeleteMessageBatch(entries []SQSDeleteMessageEntry) ([]SQSDeleteMessageEntry, error)

DeleteMessageBatch mocks base method.

func (*MockInterface) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockInterface) SendMessageBatch

func (m *MockInterface) SendMessageBatch(entries []SQSMessageEntry) ([]SQSMessageEntry, error)

SendMessageBatch mocks base method.

type MockInterfaceMockRecorder

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

MockInterfaceMockRecorder is the mock recorder for MockInterface.

func (*MockInterfaceMockRecorder) DeleteMessageBatch

func (mr *MockInterfaceMockRecorder) DeleteMessageBatch(entries any) *gomock.Call

DeleteMessageBatch indicates an expected call of DeleteMessageBatch.

func (*MockInterfaceMockRecorder) SendMessageBatch

func (mr *MockInterfaceMockRecorder) SendMessageBatch(entries any) *gomock.Call

SendMessageBatch indicates an expected call of SendMessageBatch.

type SQSDeleteMessageEntry

type SQSDeleteMessageEntry struct {
	Id            *string
	ReceiptHandle *string
}

type SQSMessageEntry

type SQSMessageEntry struct {
	Id                     *string
	MessageBody            *string
	DelaySeconds           int32
	MessageDeduplicationId *string
	MessageGroupId         *string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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