This document provides guidance for AI agents and automated systems working with the RabbitMQ Stream Go Client codebase.
This is a Go client library for RabbitMQ Stream Queues. The client provides high-level abstractions for producing and consuming messages from RabbitMQ streams.
Environment(pkg/stream/environment.go): Main entry point that manages connections to broker(s)Producer(pkg/stream/producer.go): Interface for publishing messages to streamsConsumer(pkg/stream/consumer.go): Interface for consuming messages from streamsClient(pkg/stream/client.go): Low-level TCP connection handlerSuperStreamProducer(pkg/stream/super_stream_producer.go): Producer for super streams (partitioned streams)SuperStreamConsumer(pkg/stream/super_stream_consumer.go): Consumer for super streamshapackage (pkg/ha/): High-availability components (ReliableProducer, ReliableConsumer)
pkg/stream/: Core streaming functionalitypkg/amqp/: AMQP 1.0 message encoding/decodingpkg/ha/: High-availability and reliability featurespkg/logs/: Logging utilitiespkg/message/: Message interface definitionsexamples/: Usage examples organized by featureperfTest/: Performance testing tool
- The library is generally thread-safe, but:
- Messages are NOT thread-safe - do not share messages between goroutines
- One producer/consumer per goroutine is recommended for best performance
- Connections, producers, and consumers are designed to be long-lived
- Use
errors.Is()to check for specific error types (e.g.,stream.StreamAlreadyExists) - Network errors should be handled gracefully with retry logic
- Always check errors from
NewEnvironment(),NewProducer(), andNewConsumer()
- Holding mutexes during network I/O: Always release mutexes before blocking operations
- Sharing messages between goroutines: Messages are not thread-safe
- Creating/closing connections frequently: Connections should be long-lived
- Ignoring close events: Always handle
NotifyClose()channels to detect disconnections - Not handling reconnection: Use
ReliableProducer/ReliableConsumerif auto-reconnect is needed
- Unit tests: Located alongside source files (
*_test.go) - Integration tests:
pkg/integration_test/- require running RabbitMQ server - Test helpers:
pkg/test-helper/- utilities for testing
When modifying code:
- Run existing tests:
go test ./... - Add tests for new functionality
- Integration tests may require Docker setup (see
compose/directory)
- Follow standard Go conventions
- Use meaningful variable names
- Add comments for complex logic, especially around concurrency
- Document mutex usage patterns in comments
- Use
golangci-lintfor code quality (see.github/workflows/golangci-lint.yml)
- Producers and consumers don't auto-reconnect by default
- Use
ReliableProducer/ReliableConsumerfrompkg/ha/for auto-reconnect - Always handle
NotifyClose()events to detect disconnections
- Basic usage:
examples/getting_started/getting_started.go - Reliable producer/consumer:
examples/reliable_getting_started/reliable_getting_started.go - Super streams:
examples/reliable_super_stream_getting_started/reliable_super_stream_getting_started.go - All examples: See
examples/README.md
- Build: Standard Go build (
go build) - Test:
go test ./... - Lint: Uses
golangci-lint(configured in workflows) - Docker setup: See
compose/directory for local testing environment
- Review existing patterns: Look for similar code patterns before introducing new ones
- Check mutex usage: Ensure mutexes are not held during blocking operations
- Add tests: Include unit tests for new functionality
- Update documentation: Update relevant README files if API changes
- Check examples: Ensure examples still work with changes
- Review CHANGELOG.md: Add entries for user-facing changes
- Main README:
README.md- Comprehensive user documentation - Best Practices:
best_practices/README.md- Client usage guidelines - Changelog:
CHANGELOG.md- Release history - GitHub: https://github.com/rabbitmq/rabbitmq-stream-go-client