sqssrv

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2018 License: MIT Imports: 9 Imported by: 0

README

CircleCI codecov GoDoc Go Report Card

http-sqs-service

The http-sqs-service is the lab259/http service for the Amazon Simple Queue Service (SQS).

It wraps the logic of dealing with credentials and keeping the session.

Dependencies

It depends on the lab259/http (and its dependencies, of course) itself and the aws/aws-sdk-go library.

Installation

First, fetch the library to the repository.

go get github.com/lab259/http-sqs-service

Usage

The service is designed to be "extended" and not used directly.

srv.go

package mail

import (
	"github.com/lab259/http"
	"github.com/lab259/http-sqs-service"
)

type MessageSQSService struct {
	sqssrv.SQSService
}

func (service *MessageSQSService) LoadConfiguration() (interface{}, error) {
	var configuration sqssrv.SQSServiceConfiguration

	configurationLoader := http.NewFileConfigurationLoader("/etc/mail")
	configurationUnmarshaler := &http.ConfigurationUnmarshalerYaml{}

	config, err := configurationLoader.Load(file)
	if err != nil {
		return err
	}
	return configurationUnmarshaler.Unmarshal(config, dst)
	if err != nil {
		return nil, err
	}
	return configuration, nil
}

example.go

// ...

var mq rscsrsv.MessageSQSService

func init() {
	configuration, err := mq.LoadConfiguration()
	if err != nil {
		panic(err)
	}
	err = mq.ApplyConfiguration(configuration)
	if err != nil {
		panic(err)
	}
	err = mq.Start()
	if err != nil {
		panic(err)
	}
}

// enqueueMessage enqueues a message
func enqueueMessage(message string) {
	output, err := service.SendMessage(&sqs.SendMessageInput{
		MessageBody: aws.String("this is the content of the message"),
	})
	if err != nil {
		panic(err)
	}
	// ... handles the return of the SendMessage
}

// ...

Development

mkdir -p src/github.com/lab259/http-sqs-service
git clone git@github.com:lab259/http-sqs-service.git src/github.com/lab259/http-sqs-service
cd src/github.com/lab259/http-sqs-service
make dep-ensure

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CredentialsFromStruct

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

func NewCredentialsFromStruct

func NewCredentialsFromStruct(credentials *SQSServiceConfiguration) *CredentialsFromStruct

func (*CredentialsFromStruct) IsExpired

func (*CredentialsFromStruct) IsExpired() bool

func (*CredentialsFromStruct) Retrieve

func (c *CredentialsFromStruct) Retrieve() (credentials.Value, error)

type SQSService

type SQSService struct {
	Configuration SQSServiceConfiguration
	// contains filtered or unexported fields
}

SQSService is the service which manages a service queue on the AWS.

func (*SQSService) ApplyConfiguration

func (service *SQSService) ApplyConfiguration(configuration interface{}) error

ApplyConfiguration applies a given configuration to the service.

func (*SQSService) DeleteMessage

func (service *SQSService) DeleteMessage(input *sqs.DeleteMessageInput) (*sqs.DeleteMessageOutput, error)

DeleteMessage is a wrapper for the `sqs.SQS.DeleteMessage`.

func (*SQSService) DeleteMessageBatch

func (service *SQSService) DeleteMessageBatch(input *sqs.DeleteMessageBatchInput) (*sqs.DeleteMessageBatchOutput, error)

DeleteMessageBatch is a wrapper for the `sqs.SQS.DeleteMessageBatch`.

func (*SQSService) DeleteMessageBatchWithContext

func (service *SQSService) DeleteMessageBatchWithContext(ctx context.Context, input *sqs.DeleteMessageBatchInput) (*sqs.DeleteMessageBatchOutput, error)

DeleteMessageBatchWithContext is a wrapper for the `sqs.SQS.DeleteMessageBatchWithContext`.

func (*SQSService) DeleteMessageWithContext

func (service *SQSService) DeleteMessageWithContext(ctx context.Context, input *sqs.DeleteMessageInput) (*sqs.DeleteMessageOutput, error)

DeleteMessageWithContext is a wrapper for the `sqs.SQS.DeleteMessageWithContext`.

func (*SQSService) LoadConfiguration

func (service *SQSService) LoadConfiguration() (interface{}, error)

LoadConfiguration returns

func (*SQSService) ReceiveMessage

func (service *SQSService) ReceiveMessage(input *sqs.ReceiveMessageInput) (*sqs.ReceiveMessageOutput, error)

ReceiveMessage is a wrapper for the `sqs.SQS.ReceiveMessage`.

func (*SQSService) ReceiveMessageWithContext

func (service *SQSService) ReceiveMessageWithContext(ctx context.Context, input *sqs.ReceiveMessageInput) (*sqs.ReceiveMessageOutput, error)

ReceiveMessageWithContext is a wrapper for the `sqs.SQS.ReceiveMessageWithContext`.

func (*SQSService) Restart

func (service *SQSService) Restart() error

Restart stops and then starts the service again.

func (*SQSService) RunWithSQS

func (service *SQSService) RunWithSQS(handler func(client *sqs.SQS) error) error

RunWithSQS runs a handler passing the reference of a `sqs.SQS` client.

func (*SQSService) SendMessage

func (service *SQSService) SendMessage(input *sqs.SendMessageInput) (*sqs.SendMessageOutput, error)

SendMessage is a wrapper for the `sqs.SQS.SendMessage`.

func (*SQSService) SendMessageBatch

func (service *SQSService) SendMessageBatch(input *sqs.SendMessageBatchInput) (*sqs.SendMessageBatchOutput, error)

SendMessageBatch is a wrapper for the `sqs.SQS.SendMessageBatch`.

func (*SQSService) SendMessageBatchWithContext

func (service *SQSService) SendMessageBatchWithContext(ctx context.Context, input *sqs.SendMessageBatchInput) (*sqs.SendMessageBatchOutput, error)

SendMessageBatchWithContext is a wrapper for the `sqs.SQS.SendMessageBatchWithContext`.

func (*SQSService) SendMessageWithContext

func (service *SQSService) SendMessageWithContext(ctx context.Context, input *sqs.SendMessageInput) (*sqs.SendMessageOutput, error)

SendMessageWithContext is a wrapper for the `sqs.SQS.SendMessage`.

func (*SQSService) Start

func (service *SQSService) Start() error

Start starts the redis pool.

func (*SQSService) Stop

func (service *SQSService) Stop() error

Stop erases the aws client reference.

type SQSServiceConfiguration

type SQSServiceConfiguration struct {
	QUrl     string `yaml:"q_url"`
	Region   string `yaml:"region"`
	Endpoint string `yaml:"endpoint"`
	Key      string `yaml:"key"`
	Secret   string `yaml:"secret"`
}

RedigoServiceConfiguration is the configuration for the `RedigoService`

Jump to

Keyboard shortcuts

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