README

Build Status Coverage Status Go Report Card GoDoc Mentioned in Awesome Go

rmqconn

RabbitMQ Reconnection for Golang

Wrapper over amqp.Connection and amqp.Dial. Allowing to do a reconnection when the connection is broken before forcing the call to the Close () method to be closed

Use the default method func Dial (url string) (Conner, error) to connect to the server. You can implement your connection function and pass it to rmqconn.Open("", customFunc)

Getting started

1. install
go get -u github.com/sbabiv/rmqconn

Or, using dep:

dep ensure -add github.com/sbabiv/rmqconn
2. use it
conn, err := rmqconn.Open("amqp://usr:pwd@host:5672", rmqconn.Dial)
defer conn.Close()

if err != nil {
    return
}

if conn.IsConnected() {
    ch, err := conn.GetChannel()
    if err != nil {
        return
    }
    defer ch.Close()

    err = ch.Publish("", "queueName", false, false, amqp.Publishing{
        Body: []byte("hello wolrd"),
    })
}

Licence

MIT

Author

Babiv Sergey

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrConnectionUnavailable remote server is unavailable or network is down
	ErrConnectionUnavailable = errors.New("connection unavailable")
	// ErrClsoe connection was closed earlier
	ErrClose = errors.New("connection was closed earlier")
)

Functions

This section is empty.

Types

type Conn

type Conn struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Conn connect instance

func (*Conn) Close

func (conn *Conn) Close() error

Close re-conn attempts

func (*Conn) GetChannel

func (conn *Conn) GetChannel() (*amqp.Channel, error)

func (*Conn) IsConnected

func (conn *Conn) IsConnected() bool

IsConnected return connection status

type Connecter

type Connecter interface {
	GetChannel() (*amqp.Channel, error)
	IsConnected() bool
	Close() error
}

Connecter interface for connection instance

func Open

func Open(url string, dial func(string) (Conner, error)) (Connecter, error)

Creates connection and trying to connect use Close method to stop connection attempts

type Conner

type Conner interface {
	Close() error
	NotifyClose(c chan *amqp.Error) chan *amqp.Error
	GetChannel() (*amqp.Channel, error)
}

Conner interface for wrapper Connection

func Dial

func Dial(url string) (Conner, error)

Dial function wrapper amqp.Dial For use amqp.DialConfig or amqp.DialTLS implement your func