ADorigi / rabbitmq

rabbitmq wrapper library in go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

rabbitmq

Rabbitmq wrapper library in Go.
Protocols supported: AMQP

How to Use

Module Init and dependency addition

Assuming you have go installed(I love GVM), the commands to init module and add this package's dependency are as follows

go mod init <<module name>>
go get -u github.com/adorigi/rabbitmq

Required Environment Variables:

Make these two environment variables accessible to your go executable.

RABBIT_USERNAME="<<username for rabbitmq cluster access>"
RABBIT_PASSWORD="<<password for rabbitmq cluster access>>"
RABBIT_URL="<<endpoint for rabbitmq cluster>>"
RABBIT_AMQP_PROTOCOL="<<port>>"

Sample program

package main

import (
	"context"
	"time"

    "github.com/adorigi/rabbitmq"
)

func main() {

	rabbit := rabbitmq.NewRabbit()
	rabbit.Configure()
	rabbit.ConnectSocket()
	rabbit.ConnectChannel()
	rabbit.DeclareQueue(<<queuename>>)

	ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
	defer cancel()

	body := "Hello World!"
	rabbit.PublishCTXByte(ctx, []byte(body))

	rabbit.Close()

}


About

rabbitmq wrapper library in go


Languages

Language:Go 94.4%Language:Makefile 5.6%