A reusable, copyable description of a RabbitMQ broker: image, credentials, virtual host, preloaded definitions, and plugins to enable.
More...
|
| | RabbitMQImage () |
| | A config ready to start(): image rabbitmq:3.13-management, ports 5672 + 15672 exposed, credentials guest/guest on vhost "/", ordered readiness (log line, then one diagnostics exec).
|
| RabbitMQImage & | with_image (const std::string &reference) |
| | Override the pinned image with a full reference "name[:tag]" (tag defaults to "latest") — e.g.
|
| RabbitMQImage & | with_username (std::string username) |
| | The broker's provisioned user (RABBITMQ_DEFAULT_USER).
|
| RabbitMQImage & | with_password (std::string password) |
| | The provisioned user's password (RABBITMQ_DEFAULT_PASS).
|
| RabbitMQImage & | with_vhost (std::string vhost) |
| | The default virtual host (RABBITMQ_DEFAULT_VHOST).
|
| RabbitMQImage & | with_definitions (std::filesystem::path host_json) |
| | Import a definitions JSON file (the broker's export format: exchanges, queues, bindings, policies, users, ...) at boot — the standard way to preload topology.
|
| RabbitMQImage & | with_definitions_json (std::string json) |
| | As with_definitions, from in-memory JSON bytes instead of a host file.
|
| RabbitMQImage & | with_plugin (std::string plugin) |
| | Enable a plugin that ships with the image (e.g.
|
| RabbitMQImage & | with_env (std::string key, std::string value) |
| | Set an extra environment variable — image switches beyond the typed setters.
|
| RabbitMQImage & | with_label (std::string key, std::string value) |
| | Attach a metadata label.
|
| RabbitMQImage & | with_network (std::string network) |
| | Join a user-defined network; peers resolve this container by name/alias at <alias>:5672 (kAmqpPort, not the mapped host port).
|
| RabbitMQImage & | with_network (const Network &network) |
| RabbitMQImage & | with_network_alias (std::string alias) |
| RabbitMQImage & | with_reuse (bool reuse=true) |
| | Enable container reuse (effective only when reuse is also enabled globally — see GenericImage::with_reuse).
|
| RabbitMQImage & | with_startup_timeout (std::chrono::milliseconds timeout) |
| | Budget for the whole readiness phase (default: 60s; observed cold boots take ~10s).
|
| RabbitMQImage & | with_startup_attempts (int n) |
| | Retry the whole create→start→wait sequence up to n times.
|
| RabbitMQImage & | with_customizer (std::function< void(GenericImage &)> customize) |
| | Register a callback that customizes the underlying GenericImage — the channel for every option this module does not surface (extra ports, pull policy, ...).
|
| const std::string & | username () const noexcept |
| const std::string & | password () const noexcept |
| const std::string & | vhost () const noexcept |
| GenericImage | to_generic () const |
| | Render the full configuration — env trio, definitions plumbing (seeded account + your files + the load_definitions drop-in), ordered waits, plugin hook, customizers — into a plain GenericImage: the drop-down escape hatch when you need a raw core Container instead of a RabbitMQContainer.
|
| RabbitMQContainer | start () const |
| | Create, start, and wait for the broker (the ordered readiness above).
|
A reusable, copyable description of a RabbitMQ broker: image, credentials, virtual host, preloaded definitions, and plugins to enable.
The with_* builders mutate in place and return *this by reference, so a named config can be configured incrementally and started many times. The default image is the -management variant: the same broker with the management plugin enabled, serving the HTTP API and UI on 15672 — the standard way for a test to inspect queues, connections, and messages without an AMQP client library.
Readiness is deliberately ORDERED: the "Server startup complete" log line first, one rabbitmq-diagnostics check_port_connectivity exec second. An exec-based probe that fires in the first seconds of boot can permanently prevent the broker from starting (a root-owned Erlang cookie the server's own user then cannot read) — keep the module's waits first if you add more through with_customizer.
| RabbitMQImage & testcontainers::modules::RabbitMQImage::with_definitions |
( |
std::filesystem::path | host_json | ) |
|
Import a definitions JSON file (the broker's export format: exchanges, queues, bindings, policies, users, ...) at boot — the standard way to preload topology.
Repeatable; files import in call order, later files winning on conflicting objects. The file name must end in ".json" (anything else throws here).
The configured user/vhost are seeded ALONGSIDE your file, so it only needs the application objects: RabbitMQ skips ALL default-account provisioning when definitions are imported at boot, and without the seeding a definitions file with no "users" entry would leave the broker with no users at all. Declaring the same user/vhost in your file overrides the seeded one (your file imports later). Objects must reference vhosts that exist after import — the seeded vhost is vhost(); declare any other one your objects live in.
| RabbitMQImage & testcontainers::modules::RabbitMQImage::with_plugin |
( |
std::string | plugin | ) |
|
|
inline |
Enable a plugin that ships with the image (e.g.
"rabbitmq_shovel", "rabbitmq_federation") once the broker is ready, via rabbitmq-plugins enable — additive, so the image's own enabled plugins (management, prometheus) are kept. Repeatable; all names are enabled in one command. Plugins that add listeners on new ports (MQTT, STOMP) are enabled but their ports are not published — expose them through with_customizer if you need them mapped. A failed enable (e.g. a typo'd name) fails start().
Register a callback that customizes the underlying GenericImage — the channel for every option this module does not surface (extra ports, pull policy, ...).
Customizers run when the config is rendered (start() / to_generic()), in registration order, AFTER the module's own rendering — what they set wins over the module. A wait added here runs after the module's ordered waits, which is the SAFE position (see the class note on the Erlang cookie); do not replace the module's waits. Do not set the RABBITMQ_DEFAULT_* env here either: it would desync the credential getters and amqp_url() — use the typed setters instead.