项目作者: vcabbage

项目描述 :
AMQP 1.0 client library for Go.
高级语言: Go
项目地址: git://github.com/vcabbage/amqp.git
创建时间: 2017-03-31T03:34:42Z
项目社区:https://github.com/vcabbage/amqp

开源协议:MIT License

下载


pack.ag/amqp

Go Report Card
Coverage Status
Build Status
GoDoc
MIT licensed

pack.ag/amqp is an AMQP 1.0 client implementation for Go.

NOTE: This project is no longer under active development. See issue #205 for details.

AMQP 1.0 is not compatible with AMQP 0-9-1 or 0-10, which are
the most common AMQP protocols in use today. A list of AMQP 1.0 brokers and other
AMQP 1.0 resources can be found at github.com/xinchen10/awesome-amqp.

This library aims to be stable and worthy of production usage, but the API is still subject to change. To conform with SemVer, the major version will remain 0 until the API is deemed stable. During this period breaking changes will be indicated by bumping the minor version. Non-breaking changes will bump the patch version.

Install

  1. go get -u pack.ag/amqp

Contributing

Contributions are welcome! Please see CONTRIBUTING.md.

Example Usage

  1. package main
  2. import (
  3. "context"
  4. "fmt"
  5. "log"
  6. "time"
  7. "pack.ag/amqp"
  8. )
  9. func main() {
  10. // Create client
  11. client, err := amqp.Dial("amqps://my-namespace.servicebus.windows.net",
  12. amqp.ConnSASLPlain("access-key-name", "access-key"),
  13. )
  14. if err != nil {
  15. log.Fatal("Dialing AMQP server:", err)
  16. }
  17. defer client.Close()
  18. // Open a session
  19. session, err := client.NewSession()
  20. if err != nil {
  21. log.Fatal("Creating AMQP session:", err)
  22. }
  23. ctx := context.Background()
  24. // Send a message
  25. {
  26. // Create a sender
  27. sender, err := session.NewSender(
  28. amqp.LinkTargetAddress("/queue-name"),
  29. )
  30. if err != nil {
  31. log.Fatal("Creating sender link:", err)
  32. }
  33. ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
  34. // Send message
  35. err = sender.Send(ctx, amqp.NewMessage([]byte("Hello!")))
  36. if err != nil {
  37. log.Fatal("Sending message:", err)
  38. }
  39. sender.Close(ctx)
  40. cancel()
  41. }
  42. // Continuously read messages
  43. {
  44. // Create a receiver
  45. receiver, err := session.NewReceiver(
  46. amqp.LinkSourceAddress("/queue-name"),
  47. amqp.LinkCredit(10),
  48. )
  49. if err != nil {
  50. log.Fatal("Creating receiver link:", err)
  51. }
  52. defer func() {
  53. ctx, cancel := context.WithTimeout(ctx, 1*time.Second)
  54. receiver.Close(ctx)
  55. cancel()
  56. }()
  57. for {
  58. // Receive next message
  59. msg, err := receiver.Receive(ctx)
  60. if err != nil {
  61. log.Fatal("Reading message from AMQP:", err)
  62. }
  63. // Accept message
  64. msg.Accept()
  65. fmt.Printf("Message received: %s\n", msg.GetData())
  66. }
  67. }
  68. }
Project Description
github.com/Azure/azure-event-hubs-go * Library for interacting with Microsoft Azure Event Hubs.
github.com/Azure/azure-service-bus-go * Library for interacting with Microsoft Azure Service Bus.
gocloud.dev/pubsub * Library for portably interacting with Pub/Sub systems.
qpid-proton AMQP 1.0 library using the Qpid Proton C bindings.

* indicates that the project uses this library.

Feel free to send PRs adding additional projects. Listed projects are not limited to those that use this library as long as they are potentially useful to people who are looking at an AMQP library.

Other Notes

By default, this package depends only on the standard library. Building with the
pkgerrors tag will cause errors to be created/wrapped by the github.com/pkg/errors
library. This can be useful for debugging and when used in a project using
github.com/pkg/errors.