rabbit

package module
v0.0.0-...-f58fe1c Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2020 License: GPL-3.0 Imports: 3 Imported by: 0

README

go-amqp

Go package that provides easy use of amqp RabbitMQ client

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AMQPClient

type AMQPClient struct {
	Connection *amqp.Connection
	Channel    *amqp.Channel
	Reception  struct {
		Queue amqp.Queue
	}
	Dispatch struct{}
}

AMQPClient contains the basic objects for a AMQ connection

func (*AMQPClient) CreateChannel

func (a *AMQPClient) CreateChannel() error

AMQPClient_CreateChannel creates a channel and saves it in struct

func (*AMQPClient) GetQueueName

func (a *AMQPClient) GetQueueName() string

AMQPClient_GetQueueName return the queue name for a receiver

func (*AMQPClient) SendMessage

func (a *AMQPClient) SendMessage(exchange, routingKey string, message interface{}) error

AMQPClient_SendMessage Deliver the message to the specified exchange, if exchange not created this will throw an error

func (*AMQPClient) SetupDispatcher

func (a *AMQPClient) SetupDispatcher(exchange, exchangeType string, isDurable, autoDelete bool) error

AMQPClient_SetupDispatcher Declares the exchanges to be used to deliver messages

func (*AMQPClient) SetupQueues

func (a *AMQPClient) SetupQueues(queueName string, queueIsDurable, autoDelete bool, routingKeys []string, exchange string) error

AMQPClient_SetupQueues Declares and binds a queue to an exchange

func (*AMQPClient) StartConnection

func (a *AMQPClient) StartConnection(username, password, host string, port int) error

AMQPClient_StartConnection Starts the connection with rabbitMQ server. Dials up and creates a channel

func (*AMQPClient) StartReceiver

func (a *AMQPClient) StartReceiver(queueName string, isDurable, autoDelete bool, routingKeys []string, exchanges interface{}, consumerTag string) (<-chan amqp.Delivery, error)

AMQPClient_StartReceiver Starts a rabbit MQ receiver with the passed configuration, returns a channel that will receive the messages, along with the connection and channel instance

Example

Checks the exchange used actually exist on a server

go runDispatching()
client, err := getConn()
if err != nil {
	log.Fatalf("Failure getting client to connect: %s", err)
}
messageChannel, err := client.StartReceiver(
	"client_test",
	false,
	false,
	[]string{""},
	"test",
)
if err != nil {
	log.Fatalf("Failure starting receive: %s", err)
}
c := <-messageChannel
fmt.Println(c.Exchange)
Output:

test

Jump to

Keyboard shortcuts

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