Skip to content
This repository was archived by the owner on May 19, 2025. It is now read-only.
junekimdevPublic archive

About

Message Queue Interface using AMQP

Resources

Stars

0 stars

Watchers

1 watching

Forks

Repository files navigation

MQI

Message Queue Interface(MQI) using AMQP

PkgGoDev Go Report Card GitHub tag (latest by date) GitHub


Getting Started

Prerequisite

You need an active running instance of RabbitMQ server somewhere you can access

Installing

go get it (pun intended 😸)

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
}

About

Message Queue Interface using AMQP

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages