This document provides guidance for AI coding assistants working with the RabbitMQ AMQP 1.0 Go Client library.
This is a Go client library for RabbitMQ 4.x that provides a wrapper around the Azure go-amqp client. The library simplifies working with AMQP 1.0 protocol in RabbitMQ, providing high-level abstractions for common operations like publishing, consuming, RPC patterns, and queue management.
github.com/Azure/go-amqp v1.5.1- Core AMQP 1.0 implementationgithub.com/google/uuid- UUID generationgithub.com/golang-jwt/jwt/v5- JWT token handling (for OAuth2)- Testing:
github.com/onsi/ginkgo/v2andgithub.com/onsi/gomega
pkg/rabbitmqamqp/ # Main package with all client functionality
- amqp_connection.go # Connection management
- amqp_consumer.go # Consumer implementation
- amqp_publisher.go # Publisher implementation
- amqp_queue.go # Queue operations
- amqp_exchange.go # Exchange operations
- amqp_management.go # Management API operations
- requester.go # RPC requester (client side)
- responder.go # RPC responder (server side)
- entities.go # Queue specifications and types
- amqp_types.go # Type aliases and interfaces
- common.go # Shared utilities and constants
- converters.go # Message conversion utilities
- address.go # Address parsing
- uri.go # URI handling
- websocket_dialer.go # WebSocket support
- log.go # Logging utilities
- life_cycle.go # Lifecycle management
- *_test.go # Test files
docs/examples/ # Example code demonstrating usage
AmqpEnvironment- Main entry point for creating connections, publishers, consumersAmqpConnection- Represents an AMQP connectionAmqpPublisher- Interface for publishing messagesAmqpConsumer- Interface for consuming messagesRequester- Interface for RPC client operations (formerly RpcClient)Responder- Interface for RPC server operations (formerly RpcServer)AmqpQueue- Interface for queue management operationsAmqpExchange- Interface for exchange operationsAmqpManagement- Interface for management API operations
Quorum- Quorum queue typeClassic- Classic queue typeStream- Stream queue typeJms- JMS queue type // for rabbitmq tanzu
IConsumerOptions- Interface for configuring consumerslinkName()- Link name (defaults to random UUID)initialCredits()- Initial credits (defaults to 256)linkFilters()- Link filters for stream consumersid()- Consumer IDvalidate()- Validates the configured consumer optionsisDirectReplyToEnable()- Indicates whether Direct Reply-To is enabled for this consumerpreSettled()- Indicates whether the consumer operates in pre-settled mode- Settle strategy is configured via
ConsumerOptions.SettleStrategyorRequesterOptions.SettleStrategyusing theConsumerSettleStrategyenum:ExplicitSettle,DirectReplyTo,PreSettled
IQueueSpecification- Interface for queue specificationsQuorumQueueSpecification- Specification for quorum queuesClassicQueueSpecification- Specification for classic queuesStreamQueueSpecification- Specification for stream queuesAutoGeneratedQueueSpecification- It is a classic queue with auto-generated nameDefaultQueueSpecification- Default queue specification. Server will decide the queue type based on the virtual host configuration.
- Interfaces typically start with
I(e.g.,IConsumerOptions,IQueueSpecification) - Private methods use lowercase (e.g.,
linkName(),initialCredits()) - Public methods use PascalCase (e.g.,
Close(),Publish()) - Constants use camelCase (e.g.,
linkPairName,managementNodeAddress)
- Functions return
erroras the last return value - Use descriptive error messages with context
- Check for nil before dereferencing pointers
- Most operations accept
context.Contextas the first parameter - Use context for cancellation and timeouts
- Always pass context through the call chain
- Use the logging functions from
log.go:Info(),Error(),Debug(),Warn()
- Logging follows structured logging patterns with key-value pairs
- Example code is provided in the
docs/examples/directory - Examples cover common use cases like publishing, consuming, RPC patterns, and management operations
- Tests use Ginkgo/Gomega framework
- Test files follow the pattern
*_test.go - Test utilities are in
test_utils.go - Integration tests may require a running RabbitMQ instance
- Use
make testto run all tests
- In v0.4.0,
RpcClientwas renamed toRequesterandRpcServerwas renamed toResponder - Always check the CHANGELOG.md for breaking changes between versions
- Define interfaces if needed (following the
Iprefix convention) - Implement the feature in the appropriate file
- Add tests in corresponding
*_test.gofile - Update documentation if needed
- Add examples in
docs/examples/if applicable
- Check for related tests and update them
- Ensure backward compatibility or document breaking changes
- Update CHANGELOG.md for user-facing changes
- Follow existing code patterns and conventions
- This library wraps Azure's go-amqp client
- Type aliases are defined in
amqp_types.go(e.g.,DeliveryState,StateAccepted) - When updating Azure dependency, check for breaking changes in their changelog