Skip to content

Latest commit

 

History

History
101 lines (77 loc) · 3.36 KB

README.md

File metadata and controls

101 lines (77 loc) · 3.36 KB

بِسْمِ اللّٰهِ الرَّحْمٰنِ الرَّحِيْمِ


السَّلاَمُ عَلَيْكُمْ وَرَحْمَةُ اللهِ وَبَرَكَاتُهُ


ٱلْحَمْدُ لِلَّهِ رَبِّ ٱلْعَٰلَمِينَ

ٱلْحَمْدُ لِلَّهِ رَبِّ ٱلْعَٰلَمِينَ

ٱلْحَمْدُ لِلَّهِ رَبِّ ٱلْعَٰلَمِينَ


اللَّهُمَّ صَلِّ عَلَى مُحَمَّدٍ ، وَعَلَى آلِ مُحَمَّدٍ ، كَمَا صَلَّيْتَ عَلَى إِبْرَاهِيمَ وَعَلَى آلِ إِبْرَاهِيمَ ، إِنَّكَ حَمِيدٌ مَجِيدٌ ، اللَّهُمَّ بَارِكْ عَلَى مُحَمَّدٍ ، وَعَلَى آلِ مُحَمَّدٍ ، كَمَا بَارَكْتَ عَلَى إِبْرَاهِيمَ ، وَعَلَى آلِ إِبْرَاهِيمَ ، إِنَّكَ حَمِيدٌ مَجِيدٌ

RabbitMQ Client

Coverage Status CircleCI Go Report Card

The rabbitmq client is built using the fairyhunter13/amqpwrapper package. This package can manage the topology of queue's network inside the RabbitMQ. This package simplifies the management and usage of publishing and consuming for RabbitMQ.

Example

This is an example how to use this package.

Publish and Subscribe

This is an example of go code to publish and subscribe using this package.

package main

import (
	"fmt"
	"log"
	"time"

	"github.com/fairyhunter13/amqpwrapper"
	"github.com/fairyhunter13/rabbitmqclient"
	"github.com/streadway/amqp"
)

func main() {
	uriHost := fmt.Sprintf("amqp://guest:guest@%s:5672", "localhost")
	conn, err := amqpwrapper.NewManager(uriHost, amqp.Config{})
	if err != nil {
		log.Panicln(err)
	}

	container, err := rabbitmqclient.NewContainer(conn)
	if err != nil {
		log.Panicln(err)
	}

	err = container.
		SetExchangeName("integration-test").
		Publish(
			"",
			"example",
			*new(rabbitmqclient.OtherPublish).
				SetPersistent().
				SetBody([]byte("test payload")),
		)
	if err != nil {
		log.Panicln(err)
	}

	var result string
	testHandler := func(ch *amqp.Channel, msg amqp.Delivery) {
		msg.Ack(false)
		result = string(msg.Body)
	}
	err = container.
		Consumer().
		SetTopic("example").
		Consume(0, testHandler)
	if err != nil {
		log.Panicln(err)
	}

	time.Sleep(2 * time.Second)
	if result != "test payload" {
		log.Panicf("Expected: %v Actual: %v doesn't match.", "test payload", result)
	}
}

Topology

For this example, see this test code inside TestRabbitMQNetwork function.

Author

fairyhunter13

License

The source code inside this package is available under the MIT License.