lepus

package module
v0.0.0-...-8ea9634 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2018 License: MIT Imports: 7 Imported by: 0

README

lepus

GoDoc Go Report Card

Simple wrapper around streadway/amqp with syncronous functions.

Installation

Install:

go get -u github.com/edadeal/lepus

Import:

import "github.com/edadeal/lepus"

Quickstart

func main() {
	conn, err := amqp.Dial("amqp://lepus:lepus@127.0.0.1:5672/lepus")
	if err != nil {
		log.Fatal(err)
    }
    
    defer conn.Close()

    ch, err := lepus.SyncChannel(conn.Channel())
	if err != nil {
		t.Fatal(err)
    }
    
    _, err = ch.QueueDeclare(
		"test", // name
		true,   // durable
		false,  // delete when unused
		false,  // exclusive
		false,  // no-wait
		nil,    // arguments
    )
    if err != nil {
		t.Fatal(err)
    }

    state, err := ch.PublishAndWait(
		"",     // exchange
		"test", // routing key
		true,   // mandatory
		false,
		amqp.Publishing{
			DeliveryMode: amqp.Persistent,
			ContentType:  "text/plain",
			Body:         []byte("Hello, lepus!"),
		},
	)

	if err != nil {
		t.Fatal(err)
    }
    
    log.Printf("Published: %t", state == lepus.StatePublished)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MustPublish

func MustPublish(s State, err error) error

MustPublish can be used as a wrapper around `PublishAndWait` and `NackDelayed` methods if you didn't want to process error and state separately.

Types

type Channel

type Channel struct {
	*amqp.Channel
	// contains filtered or unexported fields
}

Channel is a wrapper around async AMQP channel

func SyncChannel

func SyncChannel(ch *amqp.Channel, err error) (*Channel, error)

SyncChannel returns channel wrapper

func (*Channel) ConsumeMessages

func (c *Channel) ConsumeMessages(queue, consumer string, autoAck, exclusive, noLocal, noWait bool, args amqp.Table) (<-chan Delivery, error)

ConsumeMessages returns chan of wrapped messages from queue

func (*Channel) PublishAndWait

func (c *Channel) PublishAndWait(exchange, key string, mandatory, immediate bool, msg amqp.Publishing) (State, error)

PublishAndWait sends message to queue and waits for response

func (*Channel) WithTimeout

func (c *Channel) WithTimeout(d time.Duration)

WithTimeout sets publish wait timeout

type Delivery

type Delivery struct {
	amqp.Delivery
	// contains filtered or unexported fields
}

Delivery is a superset of amqp.Delivery

func (*Delivery) Ack

func (d *Delivery) Ack(multiple bool) error

Ack is a concurrent safe wrapper around standart AMQP Ack

func (*Delivery) Nack

func (d *Delivery) Nack(multiple, requeue bool) error

Nack is a concurrent safe wrapper around standart AMQP Nack

func (*Delivery) NackDelayed

func (d *Delivery) NackDelayed(multiple, mandatory, immediate bool) (State, error)

NackDelayed nacks message without requeue and publishes it again without modification back to tail of queue

func (*Delivery) Reject

func (d *Delivery) Reject(requeue bool) error

Reject is a concurrent safe wrapper around standart AMQP Reject

type State

type State int32

State indicates publishing state of message

const (
	StateUnknown   State = iota // Unknown
	StatePublished              // Published
	StateReturned               // Returned
	StateTimeout                // Timeout
	StateClosed                 // Closed
)

states

func (State) String

func (i State) String() string

Jump to

Keyboard shortcuts

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