Files
floci/docs/services/amazonmq.md
T
Ahmed khaled 188854f2df feat(amazonmq): add Amazon MQ broker control plane backed by RabbitMQ (#1642)
* feat(amazonmq): add Amazon MQ broker control plane for RabbitMQ

* feat(amazonmq): provision RabbitMQ container with rollback

Back a broker with a real rabbitmq:3-management container, following the
MSK/ElastiCache container-manager pattern.

- RabbitMqManager starts the container, publishes AMQP (5672) and
  management (15672) ports, and resolves the broker endpoints
- Service branches on the mock flag; real brokers stay
  CREATION_IN_PROGRESS until a readiness poller observes the management
  API answering, then flip to RUNNING
- Rollback on failed provisioning: the manager removes the half-built
  container and the broker is persisted as CREATION_FAILED
- @PreDestroy stops containers on shutdown; DeleteBroker stops and
  removes the container and its storage

Readiness probes the management UI root (no auth) to avoid RabbitMQ's
loopback-only guest user over Docker port mapping.

* feat(amazonmq): seed broker admin user and reject ActiveMQ-only User API

Amazon MQ's standalone User API (CreateUser/DescribeUser/ListUsers/
DeleteUser) applies only to ActiveMQ brokers; AWS rejects it for RabbitMQ
and directs callers to the RabbitMQ web console. CreateBroker now requires
exactly one broker user (validated against AWS password rules) which is
seeded into the container via RABBITMQ_DEFAULT_USER/PASS, sidestepping
RabbitMQ's loopback-only guest restriction.

* test(amazonmq): SDK compatibility test against live RabbitMQ broker

Adds AmazonMqTest exercising the real container path via the AWS SDK MqClient:
CreateBroker provisions a rabbitmq:3-management container, the broker
transitions to RUNNING once its management API answers, endpoints are
published, the ActiveMQ-only User API is rejected, and DeleteBroker tears the
container down. Uses JUnit Assumptions to skip cleanly when Docker is absent.

* fix(amazonmq): harden error handling, persistence, and shutdown teardown

- Redact the provisioning failure 500: log the cause, return a generic AWS
  error envelope instead of leaking e.getMessage() (which can be null).
- Add @JsonIgnoreProperties(ignoreUnknown = true) to Broker, MqUser, and
  BrokerInstance so old persisted snapshots survive field changes.
- Wire RabbitMQ container teardown into EmulatorLifecycle.onStop() via
  RabbitMqManager.stopAll(), alongside the other container managers; the
  service @PreDestroy now only stops the readiness poller.

* docs(amazonmq): add Amazon MQ service page and bump service count to 66

Adds docs/services/amazonmq.md, lists Amazon MQ in the services overview and
README service tables, and updates the "65 -> 66 AWS services" count across
docs/index.md, docs/services/index.md, and README.md.

* fix(amazonmq): reject RebootBroker unless the broker is RUNNING

RebootBroker unconditionally set the broker to RUNNING, so a non-RUNNING
broker (e.g. CREATION_FAILED, which has no backing container) was silently
promoted to RUNNING and never reconciled by the readiness poller. AWS allows
RebootBroker only on a broker in the RUNNING state; guard it and return a 400
otherwise, matching the Amazon MQ API ("You can reboot only a broker with the
RUNNING status").

* fix(amazonmq): close readiness-probe connection and log tolerated failures

isReady() opened an HttpURLConnection but never disconnected it; since the
probe runs every 2s per pending broker this leaked sockets. Disconnect in a
finally block, and log the tolerated failure at debug with broker/URL context
(AGENTS.md: no empty catch; avoid noise in hot paths) instead of swallowing it.

* fix(amazonmq): tear down broker container by deterministic name after restart

containerId is in-memory bookkeeping (intentionally not persisted, since the
Broker model is serialized straight to DescribeBroker and must not leak it).
After an emulator restart it is null, so stopContainer() previously returned
early and left the container running. It now falls back to the deterministic
container name (floci-amazonmq-{brokerId}) so an explicit DeleteBroker still
removes a container left over from a previous run. Documented the field and
added RabbitMqManagerTest covering both the id and name-fallback paths.

* fix(amazonmq): keep admin password in-memory only and fail loudly if absent

The admin password is a secret used solely to seed the RabbitMQ container at
create time. Persisting it (to make it survive a restart) would write the
credential in cleartext to amazonmq-brokers.json, which the project's security
rule prohibits. It stays in-memory only via @JsonIgnore; startContainer (the
only consumer, called from CreateBroker) now throws if the password is absent
rather than seeding a null credential. Added MqUserTest asserting the password
is never serialized and round-trips to null.

* fix(amazonmq): persist broker volumeId/accountId/containerId without leaking them

These internal fields were @JsonIgnore'd, so they were absent from
amazonmq-brokers.json. After a restart in persistent mode volumeId was null
(removeBrokerStorage could not locate the named volume, leaking it) and
accountId was null (the readiness poller wrote brokers via the non-account-aware
path). Unlike the admin password, these are not secrets, so they should persist.

Remove @JsonIgnore so they round-trip through storage, and build the
DescribeBroker response explicitly in the controller so they are still never
exposed to clients (matches MskCluster, which persists volumeId/containerId).
Adds BrokerTest (round-trip) and asserts the describe response omits them.
2026-07-03 00:01:54 -05:00

3.5 KiB

Amazon MQ (RabbitMQ)

Protocol: REST-JSON Endpoint: http://localhost:4566/

Floci emulates Amazon MQ by orchestrating RabbitMQ containers. Each broker is backed by a real rabbitmq:3-management container, so AMQP clients and the RabbitMQ management console work against the published endpoints.

Only the RabbitMQ engine and the SINGLE_INSTANCE deployment mode are supported; CreateBroker rejects ACTIVEMQ and the multi-AZ deployment modes.

Supported Actions

Action Description
CreateBroker Provisions a RabbitMQ container and seeds the admin user
DescribeBroker Get broker metadata, state, and connection endpoints
ListBrokers List all emulated brokers
DeleteBroker Stops and removes the RabbitMQ container
RebootBroker Reboots the broker

User management

Amazon MQ's user API (CreateUser, DescribeUser, ListUsers, UpdateUser, DeleteUser) applies only to ActiveMQ brokers. As on real AWS, Floci rejects these operations for RabbitMQ brokers with a BadRequestException. Manage RabbitMQ users through the RabbitMQ management console. The broker's initial administrator is supplied in the CreateBroker Users list (exactly one user is required) and seeded into the container.

Configuration

Variable Default Description
FLOCI_SERVICES_AMAZONMQ_ENABLED true Enable or disable the service
FLOCI_SERVICES_AMAZONMQ_MOCK false true = metadata-only CRUD, no Docker containers
FLOCI_SERVICES_AMAZONMQ_DEFAULT_IMAGE rabbitmq:3-management Docker image for RabbitMQ broker containers

How it works

When mock is set to false (default), Floci uses the Docker API to start a RabbitMQ container for each created broker. For Docker socket setup, private registry authentication, and other Docker settings see Docker Configuration.

  • Port Mapping: The AMQP port (5672) and the management UI (15672) are each mapped to a dynamic host port. Use the endpoints returned by DescribeBroker rather than a fixed port.
  • Admin user: The CreateBroker user is seeded via RABBITMQ_DEFAULT_USER / RABBITMQ_DEFAULT_PASS. Unlike the built-in guest user (which RabbitMQ restricts to loopback connections), this user can authenticate over the mapped port.
  • Persistence: Each broker gets a named Docker volume. In memory mode the volume is removed on broker delete; in persistent modes it is retained unless FLOCI_STORAGE_PRUNE_VOLUMES_ON_DELETE=true.
  • Readiness: The broker state transitions to RUNNING once the RabbitMQ management API answers on its port.

Examples

export AWS_ENDPOINT_URL=http://localhost:4566

# Create a broker (exactly one admin user is required for RabbitMQ)
aws mq create-broker \
  --broker-name my-broker \
  --engine-type RABBITMQ \
  --engine-version "3.13" \
  --deployment-mode SINGLE_INSTANCE \
  --host-instance-type mq.t3.micro \
  --no-publicly-accessible \
  --auto-minor-version-upgrade \
  --users '[{"Username":"admin","Password":"AdminPass123","ConsoleAccess":true}]' \
  --endpoint-url $AWS_ENDPOINT_URL

# Describe a broker (poll until BrokerState is RUNNING)
BROKER_ID=$(aws mq list-brokers --query 'BrokerSummaries[0].BrokerId' --output text --endpoint-url $AWS_ENDPOINT_URL)
aws mq describe-broker --broker-id $BROKER_ID --endpoint-url $AWS_ENDPOINT_URL

# Delete a broker
aws mq delete-broker --broker-id $BROKER_ID --endpoint-url $AWS_ENDPOINT_URL