sqsc

package module
v0.0.0-...-494d263 Latest Latest
Warning

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

Go to latest
Published: May 20, 2021 License: MIT Imports: 5 Imported by: 1

README

sqs client

wtf is it?

a very very very simple sqs client package in go


usage
configs
type Config struct {
	ID       string //<< aws account id
	Key      string //<< aws auth key - leave blank for no auth
	Secret   string //<< aws account secret - leave blank for no auth
	Region   string //<< aws region
	Queue    string //<< queue name - not needed if url provided
	URL      string //<< queue url - not needed if queue provided
	Endpoint string //<< aws endpoint
	Retries  int    //<< max retries
	Timeout  int    //<< visibility timeout (seconds)
	Wait     int    //<< wait time (seconds)
}
new client
cli, err := sqsc.New(&sqsc.Config{
    ...
})
produce a message
id, err := cli.Produce("my cool message", del)
  • del - the delay for the message (just use 0)
  • id - the message id
  • err - any error
consume a message
bod, rh, err := cli.Consume()
  • bod - the message body
  • rh - the receipt handle (use for deleting message)
  • err - any error

note: if bod == "" && rh == "" && err == nil then the queue is empty, or no messages are visible

delete a message
res, err = cli.Delete(rh)
  • rh - the receipt handle (from cli.Consume())
  • res - the delete response (empty if successful)
  • err - any error

example
package main

import (
	"fmt"
	"github.com/vestiaire-collective/sqsc"
	"os"
)

func main() {
	bod := os.Args[1]

	cli, err := sqsc.New(&sqsc.Config{
		Region:   "us-east-1",
		URL:      "http://localhost:4100/queue/job",
		Endpoint: "http://127.0.0.1:4100",
	})

	res, err := cli.Produce(bod, 0)

	fmt.Printf("produce response: %+v\n", res)
	fmt.Printf("produce error:    %+v\n", err)

	res, rh, err := cli.Consume()

	fmt.Printf("consume response:       %+v\n", res)
	fmt.Printf("consume receipt handle: %+v\n", rh)
	fmt.Printf("consume error:          %+v\n", err)

	res, err = cli.Delete(rh)

	fmt.Printf("delete response: %+v\n", res)
	fmt.Printf("delete error:    %+v\n", err)
}

notes and junk

  • this is a super simple client, intentionally
  • if you need to get more fancy, fork it or build your own
  • please feel free to contribute, but do not complicate
  • please report any bugs or feature requests in the "issues" tab

merci et bonne journee

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	ID       string //<< aws account id
	Key      string //<< aws auth key - leave blank for no auth
	Secret   string //<< aws account secret - leave blank for no auth
	Region   string //<< aws region
	Queue    string //<< queue name - not needed if url provided
	URL      string //<< queue url - not needed if queue provided
	Endpoint string //<< aws endpoint
	Retries  int    //<< max retries
	Timeout  int    //<< visibility timeout (seconds)
	Wait     int    //<< wait time (seconds)
}

the client configs

type SQSC

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

the client

func New

func New(cfg *Config) (*SQSC, error)

creates a new client instance

func (*SQSC) Consume

func (c *SQSC) Consume() (string, string, error)

consume a single message from the queue

returns - the message body - the receipt handle (use for deleting messages) - any error

func (*SQSC) Delete

func (c *SQSC) Delete(rh string) (string, error)

delete a message from the queue

rh - the receipt handle (from sqsc.Consume())

returns - the response (will be empty if success) - any error

func (*SQSC) Produce

func (c *SQSC) Produce(bod string, del int) (string, error)

produce a new message on the queue

bod - the message body del - the delay in seconds (usually just use 0)

returns - the message id - error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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