Skip to content
/ lepus Public

Golang wrapper around AMQP client with synchronous operations

License

Notifications You must be signed in to change notification settings

edadeal/lepus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lepus

GoDoc Go Report Card

Simple wrapper around streadway/amqp with syncronous functions.

Installation

Install:

go get -u github.com/edadeal/lepus

Import:

import "github.com/edadeal/lepus"

Quickstart

func main() {
	conn, err := amqp.Dial("amqp://lepus:[email protected]:5672/lepus")
	if err != nil {
		log.Fatal(err)
    }
    
    defer conn.Close()

    ch, err := lepus.SyncChannel(conn.Channel())
	if err != nil {
		t.Fatal(err)
    }
    
    _, err = ch.QueueDeclare(
		"test", // name
		true,   // durable
		false,  // delete when unused
		false,  // exclusive
		false,  // no-wait
		nil,    // arguments
    )
    if err != nil {
		t.Fatal(err)
    }

    state, err := ch.PublishAndWait(
		"",     // exchange
		"test", // routing key
		true,   // mandatory
		false,
		amqp.Publishing{
			DeliveryMode: amqp.Persistent,
			ContentType:  "text/plain",
			Body:         []byte("Hello, lepus!"),
		},
	)

	if err != nil {
		t.Fatal(err)
    }
    
    log.Printf("Published: %t", state == lepus.StatePublished)
}