项目作者: edadeal

项目描述 :
Golang wrapper around AMQP client with synchronous operations
高级语言: Go
项目地址: git://github.com/edadeal/lepus.git
创建时间: 2018-06-19T12:03:32Z
项目社区:https://github.com/edadeal/lepus

开源协议:MIT License

下载


lepus

GoDoc
Go Report Card

Simple wrapper around streadway/amqp with syncronous functions.

Installation

Install:

  1. go get -u github.com/edadeal/lepus

Import:

  1. import "github.com/edadeal/lepus"

Quickstart

  1. func main() {
  2. conn, err := amqp.Dial("amqp://lepus:lepus@127.0.0.1:5672/lepus")
  3. if err != nil {
  4. log.Fatal(err)
  5. }
  6. defer conn.Close()
  7. ch, err := lepus.SyncChannel(conn.Channel())
  8. if err != nil {
  9. t.Fatal(err)
  10. }
  11. _, err = ch.QueueDeclare(
  12. "test", // name
  13. true, // durable
  14. false, // delete when unused
  15. false, // exclusive
  16. false, // no-wait
  17. nil, // arguments
  18. )
  19. if err != nil {
  20. t.Fatal(err)
  21. }
  22. state, err := ch.PublishAndWait(
  23. "", // exchange
  24. "test", // routing key
  25. true, // mandatory
  26. false,
  27. amqp.Publishing{
  28. DeliveryMode: amqp.Persistent,
  29. ContentType: "text/plain",
  30. Body: []byte("Hello, lepus!"),
  31. },
  32. )
  33. if err != nil {
  34. t.Fatal(err)
  35. }
  36. log.Printf("Published: %t", state == lepus.StatePublished)
  37. }