# README
MQI
Message Queue Interface(MQI) using AMQP
Getting Started
Prerequisite
You need an active running instance of RabbitMQ server somewhere you can access
Installing
go get it (pun intended :smile_cat:)
go get github.com/JuneKimDev/mqi
Usage
package main
import (
"log"
"sync"
"github.com/JuneKimDev/mqi"
"github.com/streadway/amqp"
)
// Consumer worker function
func mockConsumerFunc(msg amqp.Delivery) error {
log.Println("Inside of mockConsumerFunc | Test consumer function")
log.Println(msg.Body)
err := mqi.Publish("test.exchangeAnother", "test.topic3", amqp.Publishing{
ContentType: "text/plain",
Body: []byte("Great job")})
if err != nil {
return err
}
return nil
}
// RabbitMQ setup
func getMockChannelWithConsumer() mqi.Channel {
return mqi.GetChannel().
WithBroadcast(NewBroadcast("test.broadcast").
AddQueue(NewBroadcastQueue().
AddTopic(NewTopic("test.bctp")).
AddConsumer(NewConsumer("test.bccsm").WithFunc(mockFunc)))).
WithExchange(NewExchange("test.exchange").
AddQueue(NewQueue("test.q1").
AddTopic(NewTopic("test.topic1")).
AddConsumer(NewConsumer("test.consumer1").WithFunc(mockFunc))).
AddQueue(NewQueue("test.q2").
AddTopic(NewTopic("test.topic2")).
AddConsumer(NewConsumer("test.consumer2").WithFunc(mockFunc))))
}
func main() {
var forever sync.WaitGroup
forever.Add(1)
// Connect to RabbitMQ
getMockChannelWithConsumer().Start()
log.Println("The app is running in forever loop")
forever.Wait() // Prevents service from exiting
}
# Functions
AddTempQueue adds a queue which gets auto-deleted after execution of consumer function.
Close closes connection and channels.
GetChannel returns current Channel.
NewBroadcast constructs an exchange for broadcast.
NewBroadcastQueue constructs a broadcast queue.
NewChannel constructor.
NewConsumer constructs a consumer.
NewExchange constructs an exchange.
NewQueue constructs a queue.
NewTempConsumer constructs a temporary consumer.
NewTempQueue constructs a temporary queue.
NewTopic constructor.
Publish publishes a message with a topic to Exchange.