Skip to main content

Record and replay tool for RabbitMQ

Project description

Casablanca

Casablanca is a Python package designed to record and replay messages from/to RabbitMQ. Primarily intended as a developer tool for automated testing, Casablanca can also be used to populate RabbitMQ queues with data from static files for application or production use.


Features

Casablanca provides the following key features:

  • Record messages from one or more RabbitMQ queues.
  • Replay recorded messages to RabbitMQ queues.
  • Seamlessly integrate into automated testing workflows and CI/CD pipelines.
  • Populate RabbitMQ queues in production or application code from static files.
  • Command-line interface (CLI) for easy usage.
  • Python API for advanced integrations within custom workflows.
  • Flexible configuration options for RabbitMQ and file handling.

Prerequisites

You will need the following before using Casablanca:

  • Python 3.7 or higher
  • RabbitMQ installed and running
  • pip for Python package management

Installation

Casablanca uses pyproject.toml (PEP 517/518) for building and installing.

Installing Casablanca in Development Mode

Clone the repository and install in editable mode:

git clone https://github.com/your-repo/casablanca.git
cd casablanca
pip install -e .

Installing Casablanca for Production

For a standard production installation:

pip install .

Usage

Casablanca supports recording and replaying RabbitMQ messages either via its Command-Line Interface (CLI) or as a Python API for more advanced use-cases.

Recording Messages

Use Casablanca to record messages from RabbitMQ queues. Messages can be stored in a variety of formats (e.g., log files, JSON).

Example CLI Usage for Recording

casablanca record --queue my-queue --output messages.log --host localhost --port 5672

This command connects to RabbitMQ, listens to the my-queue, and records all messages into messages.log.

Replaying Messages

Replay stored messages back into RabbitMQ queues. This is helpful for testing workflows or initializing queues from predefined data.

Example CLI Usage for Replaying

casablanca replay --input messages.log --queue replay-queue --host localhost --port 5672

This replays all the messages saved in messages.log into the specified RabbitMQ replay-queue.


Configuration

Casablanca allows configuration via:

  1. Command-line arguments (e.g., --host, --queue, --output)
  2. Environment variables (e.g., RABBITMQ_HOST, RABBITMQ_PORT)
  3. Configuration files (e.g., config.yaml or config.json).

Testing

Casablanca includes both unit tests and functional tests to ensure correctness and reliability. Testing is an integral part of the source code, with unit tests existing alongside the implementation they validate.

Running Unit Tests

Unit tests exist side-by-side with the code they test. For example: /casablanca/ recorder.py # Implementation Code replayer.py
tests/ recorder_test.py # Unit Tests for recorder.py replayer_test.py # Unit Tests for replayer.py

Run unit tests by simply running pytest over the source code directory:

pytest casablanca/

Unit tests do not require a running RabbitMQ instance and are limited to verifying the internal logic and behavior of individual components.

Running Functional Tests

Functional tests validate the interaction of Casablanca with an active RabbitMQ server. These tests ensure that messages can be correctly recorded and replayed.

Run functional tests with:

pytest functional_tests/

Make sure RabbitMQ is running locally before executing functional tests.

Running All Tests

To run both unit tests and functional tests together:

pytest

Containerized Tests (Optional)

For testing Casablanca in containerized environments, you can use Docker:

docker-compose build
docker-compose up
pytest

CLI Shortcut for Container Tests

You can also run containerized tests via a CLI command:

casablanca test

Examples

Below are some practical examples of Casablanca usage:

Record Messages from Multiple Queues

Record messages from multiple queues in RabbitMQ and save them into separate files:

casablanca record --queue queue1 --output queue1.log
casablanca record --queue queue2 --output queue2.log

Replay Messages with Delays

Replay recorded messages into RabbitMQ at a controlled pace by adding a delay between each message:

casablanca replay --input messages.log --queue test-queue --delay 1

This replays the messages in messages.log to test-queue, introducing a 1-second delay between each message.

Load Testing with Recorded Data

Use recorded data to simulate load testing by replaying messages at high speeds:

casablanca replay --input large-dataset.log --queue stress-test-queue --parallel-workers 10

This replays large datasets using 10 workers to stress-test-queue for performance testing.


Contribution

We welcome contributions to improve Casablanca! Here's how you can get involved:

  1. Report Issues: Found a bug? Have suggestions? Open an issue on GitHub.
  2. Submit Pull Requests: Fork the repository, make your changes, and submit a PR.
  3. Improve Documentation: Help expand or enhance the documentation.
  4. Add Tests: Write new tests (both unit and functional) to improve code coverage and reliability.

License

Casablanca is licensed under [Your Preferred Open Source License]. See the LICENSE file in the repository for further details.


Feedback

We’d love to hear your feedback! If you encounter any issues, have suggestions, or want to request a feature, feel free to open an issue or contact the maintainers. Happy coding with Casablanca! 🎉

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

casablanca-0.0.0.tar.gz (13.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

casablanca-0.0.0-py3-none-any.whl (16.4 kB view details)

Uploaded Python 3

File details

Details for the file casablanca-0.0.0.tar.gz.

File metadata

  • Download URL: casablanca-0.0.0.tar.gz
  • Upload date:
  • Size: 13.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.13.1 Linux/6.8.0-51-generic

File hashes

Hashes for casablanca-0.0.0.tar.gz
Algorithm Hash digest
SHA256 abc9205de831e4582374bee8009bc30581ee734159b9ec791229d72763ac89a6
MD5 cc223f541380ccaf2ca9968ce015f0bb
BLAKE2b-256 816ffb83d0ec4a5936953c767e21139e97e46b2b378f41821090ba0c5d6da2b5

See more details on using hashes here.

File details

Details for the file casablanca-0.0.0-py3-none-any.whl.

File metadata

  • Download URL: casablanca-0.0.0-py3-none-any.whl
  • Upload date:
  • Size: 16.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.13.1 Linux/6.8.0-51-generic

File hashes

Hashes for casablanca-0.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9fcaa28fa0d5432de11f36826673a010173a5ad4e7a1a2449f5a64184bfd6267
MD5 7e0394c02d421badbafd4680b24d3f4d
BLAKE2b-256 89c3a2dfe1aee898d1731ee68cd2c3839815b130f6df91a7557867b79c5e2f6f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page