jackrabbit

package module
v0.0.0-...-64a8de9 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2020 License: MIT Imports: 5 Imported by: 2

README

Introduction

High level utility library for Golang RabbitMQ connections. The library contains helper functions used to send messages over rabbitMQ queues, as well as worker functions used to connect and listen to rabbit queues

Example Usage

All functions take a RabbitConnectionConfig parameter defining the connection settings, which is defined as

type RabbitConnectionConfig struct {
	QueueURL     string `json:"queue_url" validate:"required"`
	QueueName    string `json:"queue_name"`
	ExchangeName string `json:"exchange_name"`
	ExchangeType string `json:"exchange_type"`
}

Once the connection setting is defined, the ConnectAndDeliverOverQueue and ConnectAndDeliverOverExchange functions can be used to send messages over the defined queue. Additionally, the ListenOnQueue functions can be used to listen on queues and handle any incoming messages

package main

import (
	"fmt"
	"time"
	rabbit "github.com/PSauerborn/go-jackrabbit"
	log "github.com/sirupsen/logrus"
)


func ExampleHandler(msg []byte) {
	log.Info(fmt.Sprintf("received queue message: %s", string(msg)))
}

func main() {
	// create new rabbiMQ connection settings and send message over queue
	config := rabbit.RabbitConnectionConfig{QueueURL: "amqp://guest:guest@192.168.99.100:5672/", QueueName: "new-testing-queue"}
	go rabbit.ListenOnQueue(config, ExampleHandler)

	for {
		rabbit.ConnectAndDeliverOverQueue(config, []byte("testing queue message"))
		time.Sleep(5 * time.Second)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	InvalidRabbitMQConfig   = errors.New("invalid RabbitMQ configuration")
	RabbitMQConnectionError = errors.New("cannot connect to RabbitMQ server")
)

Functions

func ConnectAndDeliverOverDurableExchange

func ConnectAndDeliverOverDurableExchange(config RabbitConnectionConfig, payload []byte) error

function used to generate new exchange to deliver message over exchange

func ConnectAndDeliverOverDurableQueue

func ConnectAndDeliverOverDurableQueue(config RabbitConnectionConfig, payload []byte) error

function used to generate new queue to deliver message over a durable queue

func ConnectAndDeliverOverExchange

func ConnectAndDeliverOverExchange(config RabbitConnectionConfig, payload []byte) error

function used to generate new exchange to deliver message over exchange

func ConnectAndDeliverOverQueue

func ConnectAndDeliverOverQueue(config RabbitConnectionConfig, payload []byte) error

function used to generate new queue to deliver message

func ListenOnQueue

func ListenOnQueue(config RabbitConnectionConfig, handler func(payload []byte)) error

function used to start blocking goroutine that connects to rabbitMQ connection and executes some handler function when messages are send over the specified queue

func ListenOnQueueWithExchange

func ListenOnQueueWithExchange(config RabbitConnectionConfig, handler func(payload []byte)) error

function used to start blocking goroutine that connects to rabbitMQ connection and executes some handler function when messages are send over the specified queue or exchange

Types

type RabbitConnectionConfig

type RabbitConnectionConfig struct {
	QueueURL     string `json:"queue_url" validate:"required"`
	QueueName    string `json:"queue_name"`
	ExchangeName string `json:"exchange_name"`
	ExchangeType string `json:"exchange_type"`
}

type RabbitMQConnection

type RabbitMQConnection struct {
	Connection *amqp.Connection
	Channel    *amqp.Channel
}

func NewRabbitConnection

func NewRabbitConnection(config RabbitConnectionConfig) (*RabbitMQConnection, error)

function used to create new rabbitMQ channel using AMQP library. channels can the be used to create new queues and exchanges

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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