pgmq-ruby/
├── lib/
│ ├── pgmq.rb # Main entry point
│ └── pgmq/
│ ├── client.rb # Main PGMQ client
│ ├── configuration.rb # Configuration management
│ ├── connection.rb # Database connection pooling
│ ├── errors.rb # Custom exception hierarchy
│ ├── message.rb # Message model
│ ├── metrics.rb # Queue metrics model
│ ├── queue_metadata.rb # Queue metadata model
│ ├── version.rb # Gem version
│ └── serializers/
│ ├── base.rb # Base serializer class
│ └── json.rb # JSON serializer (default)
├── test/
│ ├── test_helper.rb # Minitest configuration + SimpleCov
│ ├── support/
│ │ └── database_helpers.rb # Test helpers
│ └── lib/ # Unit tests (minitest/spec)
│ ├── pgmq_test.rb
│ ├── pgmq/
│ │ ├── client_test.rb
│ │ ├── connection_test.rb
│ │ ├── message_test.rb
│ │ ├── metrics_test.rb
│ │ ├── queue_metadata_test.rb
│ │ ├── errors_test.rb
│ │ ├── transaction_test.rb
│ │ ├── version_test.rb
│ │ └── client/
│ │ ├── consumer_test.rb
│ │ ├── producer_test.rb
│ │ ├── multi_queue_test.rb
│ │ ├── message_lifecycle_test.rb
│ │ ├── queue_management_test.rb
│ │ ├── maintenance_test.rb
│ │ ├── metrics_test.rb
│ │ └── topics_test.rb
├── spec/
│ └── integration/ # Integration examples (standalone scripts)
├── examples/ # Usage examples
│ ├── basic_usage.rb
│ ├── worker_pattern.rb
│ └── rails_usage.rb
├── bin/
│ └── console # Interactive console
├── docker-compose.yml # PostgreSQL with PGMQ for testing
├── Gemfile # Dependencies
├── Rakefile # Rake tasks
├── pgmq-ruby.gemspec # Gem specification
├── README.md # User documentation
├── CHANGELOG.md # Version history
├── LICENSE # LGPL-3.0 license
- Ruby 3.3 or higher
- PostgreSQL 14-18 with PGMQ extension
- Docker (optional, for running PostgreSQL with PGMQ)
# Clone the repository
git clone https://github.com/mensfeld/pgmq-ruby.git
cd pgmq-ruby
# Install dependencies
bundle install
# Start PostgreSQL with PGMQ extension (using Docker)
docker compose up -d
# Wait for PostgreSQL to be ready
sleep 5# Run all tests
bundle exec rake test
# Run specific test file
bundle exec ruby -Ilib:test test/lib/pgmq/client_test.rb
# Run with coverage report
bundle exec rake test
# Coverage report will be in coverage/index.html# Run tests
bundle exec rake test# Start interactive console with PGMQ client
bundle exec bin/console
# Inside console:
$client.create("test_queue")
$client.send("test_queue", { hello: "world" })
$client.read("test_queue", vt: 30)# Basic usage example
bundle exec ruby examples/basic_usage.rb
# Worker pattern (run as worker)
bundle exec ruby examples/worker_pattern.rb
# Worker pattern (run as producer)
bundle exec ruby examples/worker_pattern.rb producer
# Worker pattern (demo mode with test jobs)
bundle exec ruby examples/worker_pattern.rb demo
# Rails-like usage
bundle exec ruby examples/rails_usage.rb- Unit tests (
test/lib/): Minitest/spec tests for classes in isolation and with database - Integration tests (
spec/integration/): Standalone example scripts with real PostgreSQL
The project uses SimpleCov for code coverage tracking:
- Minimum coverage target: 80%
- Minimum coverage per file: 70%
- Coverage reports are generated automatically when running tests
- View coverage:
open coverage/index.html(Mac) orxdg-open coverage/index.html(Linux)
Integration tests require a running PostgreSQL instance with PGMQ extension:
# Start PostgreSQL
docker compose up -d
# Run tests
bundle exec rake test
# Stop PostgreSQL
docker compose downOverride default database connection:
export PG_HOST=localhost
export PG_PORT=5432
export PG_DATABASE=pgmq_test
export PG_USER=postgres
export PG_PASSWORD=postgres
bundle exec rake test# Build gem
bundle exec rake build
# Install locally
bundle exec rake install
# Release to RubyGems (requires credentials)
bundle exec rake release- Uses
connection_poolgem for thread-safe connection pooling - Supports multiple connection strategies:
- Connection strings (
postgres://...) - Hash of parameters
- Existing
PG::Connectionobjects - Environment variables
- Connection strings (
- Auto-detects Rails/ActiveRecord connections (future)
- Pluggable serializer system
- JSON serializer included (default)
- Easy to add custom serializers (implement
PGMQ::Serializers::Base)
Custom exception hierarchy:
PGMQ::Errors::BaseError- Base errorPGMQ::Errors::ConnectionError- Connection failuresPGMQ::Errors::QueueNotFoundError- Queue doesn't existPGMQ::Errors::MessageNotFoundError- Message not foundPGMQ::Errors::SerializationError- Serialization failuresPGMQ::Errors::ConfigurationError- Invalid configurationPGMQ::Errors::InvalidQueueNameError- Invalid queue name
-
Fork the repository
-
Create your feature branch (
git checkout -b feature/my-new-feature) -
Write tests for your changes
-
Implement your feature
-
Ensure tests pass:
bundle exec rake test -
Commit your changes (
git commit -am 'Add some feature') -
Push to the branch (
git push origin feature/my-new-feature) -
Create a new Pull Request
- Follow Ruby style guide
- Write YARD documentation for public methods
- Keep methods small and focused
- Prefer composition over inheritance
- Write tests for all new features
- Maintain or improve code coverage
- Use descriptive test names
- Follow AAA pattern (Arrange, Act, Assert)
- Mock external dependencies in unit tests
- Use real database for integration tests
- Update version in
lib/pgmq/version.rb - Update
CHANGELOG.mdwith changes - Commit changes:
git commit -am "Release v0.X.0" - Create git tag:
git tag v0.X.0 - Push commits and tags:
git push && git push --tags - Build and release gem:
bundle exec rake release
- Reserve gem name on RubyGems
- Basic project structure
- Queue management (create, drop, list)
- Message operations (send, read, delete)
- Batch operations
- Archive support
- Metrics
- Connection pooling
- Comprehensive tests
- Documentation
- Rails integration (Railtie, ActiveJob adapter)
- Rake tasks for queue management
- Rails generators
- Job processor framework
- Worker process management
- Retry strategies with exponential backoff
- Instrumentation and observability
- Performance benchmarks
- Security audit
- Partitioned queue support
- Unlogged queue support
- GlobalID support (for ActiveRecord objects)
- Dead letter queue pattern
# Ensure PostgreSQL is running
docker compose ps
# Check PostgreSQL logs
docker compose logs postgres
# Restart PostgreSQL
docker compose restart postgres
# Reset test database
docker compose down -v
docker compose up -d# Test connection manually
psql "postgres://postgres:postgres@localhost:5432/pgmq_test"
# Check if PGMQ extension is installed
psql -c "SELECT * FROM pg_extension WHERE extname='pgmq';" \
"postgres://postgres:postgres@localhost:5432/pgmq_test"LGPL-3.0 - See LICENSE file for details