Top Related Projects
An AMQP 0-9-1 Go client maintained by the RabbitMQ team. Originally by @streadway: `streadway/amqp`
Pure Python RabbitMQ/AMQP 0-9-1 client library
Quick Overview
streadway/amqp is a Go client library for the Advanced Message Queuing Protocol (AMQP) 0-9-1. It provides a robust and efficient implementation for interacting with AMQP-compliant message brokers, such as RabbitMQ. This library enables developers to build distributed and scalable messaging systems in Go applications.
Pros
- Lightweight and efficient implementation of AMQP 0-9-1
- Well-documented API with comprehensive examples
- Supports both synchronous and asynchronous message handling
- Actively maintained with regular updates and bug fixes
Cons
- Limited to AMQP 0-9-1 protocol, not supporting newer versions
- Lacks some advanced features available in other AMQP libraries
- May require additional error handling and connection management in production environments
- Learning curve for developers new to AMQP concepts
Code Examples
- Connecting to an AMQP server:
conn, err := amqp.Dial("amqp://guest:guest@localhost:5672/")
if err != nil {
log.Fatalf("Failed to connect to AMQP server: %v", err)
}
defer conn.Close()
- Publishing a message:
ch, _ := conn.Channel()
defer ch.Close()
err = ch.Publish(
"exchange_name",
"routing_key",
false,
false,
amqp.Publishing{
ContentType: "text/plain",
Body: []byte("Hello, AMQP!"),
})
- Consuming messages:
msgs, err := ch.Consume(
"queue_name",
"",
true,
false,
false,
false,
nil,
)
for msg := range msgs {
log.Printf("Received message: %s", msg.Body)
}
Getting Started
To use streadway/amqp in your Go project, follow these steps:
-
Install the library:
go get github.com/streadway/amqp
-
Import the package in your Go code:
import "github.com/streadway/amqp"
-
Establish a connection to your AMQP server:
conn, err := amqp.Dial("amqp://guest:guest@localhost:5672/") if err != nil { log.Fatalf("Failed to connect to AMQP server: %v", err) } defer conn.Close()
-
Create a channel and start using AMQP operations:
ch, err := conn.Channel() if err != nil { log.Fatalf("Failed to open a channel: %v", err) } defer ch.Close() // Use ch to declare exchanges, queues, publish, and consume messages
Remember to handle errors appropriately and implement proper connection management for production use.
Competitor Comparisons
An AMQP 0-9-1 Go client maintained by the RabbitMQ team. Originally by @streadway: `streadway/amqp`
Pros of amqp091-go
- Officially maintained by RabbitMQ team, ensuring better alignment with AMQP 0-9-1 protocol
- More active development and frequent updates
- Improved error handling and connection recovery mechanisms
Cons of amqp091-go
- Relatively newer library, potentially less mature than streadway/amqp
- May require code changes when migrating from streadway/amqp
- Smaller community and fewer third-party resources available
Code Comparison
amqp091-go:
conn, err := amqp091.Dial("amqp://guest:guest@localhost:5672/")
ch, err := conn.Channel()
err = ch.PublishWithContext(ctx, exchange, key, mandatory, immediate, msg)
streadway/amqp:
conn, err := amqp.Dial("amqp://guest:guest@localhost:5672/")
ch, err := conn.Channel()
err = ch.Publish(exchange, key, mandatory, immediate, msg)
The main difference is the use of PublishWithContext
in amqp091-go, which allows for better context handling and cancellation. Additionally, amqp091-go uses the amqp091
package name instead of amqp
.
Both libraries provide similar functionality, but amqp091-go offers more up-to-date features and better alignment with the AMQP 0-9-1 protocol. However, streadway/amqp has a larger user base and more community resources available.
Pure Python RabbitMQ/AMQP 0-9-1 client library
Pros of Pika
- Pure Python implementation, making it easier to install and use across different platforms
- More Pythonic API, following Python conventions and idioms
- Supports both synchronous and asynchronous programming models
Cons of Pika
- Generally slower performance compared to AMQP
- Less mature and potentially less stable than AMQP
- May have fewer advanced features for complex RabbitMQ setups
Code Comparison
AMQP (Go):
conn, err := amqp.Dial("amqp://guest:guest@localhost:5672/")
ch, err := conn.Channel()
err = ch.Publish("exchange", "routing_key", false, false, amqp.Publishing{Body: []byte("message")})
Pika (Python):
connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
channel = connection.channel()
channel.basic_publish(exchange='', routing_key='queue_name', body='message')
Both libraries provide similar functionality for connecting to RabbitMQ and publishing messages. AMQP uses a more Go-idiomatic approach with multiple return values for error handling, while Pika follows Python conventions with exception handling (not shown in the example).
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Go RabbitMQ Client Library (Unmaintained Fork)
Beware of Abandonware
This repository is NOT ACTIVELY MAINTAINED. Consider using a different fork instead: rabbitmq/amqp091-go. In case of questions, start a discussion in that repo or use other RabbitMQ community resources.
Project Maturity
This project has been used in production systems for many years. As of 2022, this repository is NOT ACTIVELY MAINTAINED.
This repository is very strict about any potential public API changes. You may want to consider rabbitmq/amqp091-go which is more willing to adapt the API.
Supported Go Versions
This library supports two most recent Go release series, currently 1.10 and 1.11.
Supported RabbitMQ Versions
This project supports RabbitMQ versions starting with 2.0
but primarily tested
against reasonably recent 3.x
releases. Some features and behaviours may be
server version-specific.
Goals
Provide a functional interface that closely represents the AMQP 0.9.1 model targeted to RabbitMQ as a server. This includes the minimum necessary to interact the semantics of the protocol.
Non-goals
Things not intended to be supported.
- Auto reconnect and re-synchronization of client and server topologies.
- Reconnection would require understanding the error paths when the topology cannot be declared on reconnect. This would require a new set of types and code paths that are best suited at the call-site of this package. AMQP has a dynamic topology that needs all peers to agree. If this doesn't happen, the behavior is undefined. Instead of producing a possible interface with undefined behavior, this package is designed to be simple for the caller to implement the necessary connection-time topology declaration so that reconnection is trivial and encapsulated in the caller's application code.
- AMQP Protocol negotiation for forward or backward compatibility.
- 0.9.1 is stable and widely deployed. Versions 0.10 and 1.0 are divergent specifications that change the semantics and wire format of the protocol. We will accept patches for other protocol support but have no plans for implementation ourselves.
- Anything other than PLAIN and EXTERNAL authentication mechanisms.
- Keeping the mechanisms interface modular makes it possible to extend outside of this package. If other mechanisms prove to be popular, then we would accept patches to include them in this package.
Usage
See the 'examples' subdirectory for simple producers and consumers executables. If you have a use-case in mind which isn't well-represented by the examples, please file an issue.
Documentation
Use Godoc documentation for reference and usage.
RabbitMQ tutorials in Go are also available.
Contributing
Pull requests are very much welcomed. Create your pull request on a non-master branch, make sure a test or example is included that covers your change and your commits represent coherent changes that include a reason for the change.
To run the integration tests, make sure you have RabbitMQ running on any host,
export the environment variable AMQP_URL=amqp://host/
and run go test -tags integration
. TravisCI will also run the integration tests.
Thanks to the community of contributors.
External packages
License
BSD 2 clause - see LICENSE for more details.
Top Related Projects
An AMQP 0-9-1 Go client maintained by the RabbitMQ team. Originally by @streadway: `streadway/amqp`
Pure Python RabbitMQ/AMQP 0-9-1 client library
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot