mirror of
https://github.com/floci-io/floci.git
synced 2026-11-29 08:31:53 -05:00
Floci's shutdown removes every broker container, and nothing started them again, so after a restart with persistent storage a broker still reported RUNNING while nothing answered on its endpoints. A new container would not have helped either: RabbitMQ keeps its data under the node name, which defaults to the hostname Docker sets to the container id, so a new container on the same volume started an empty node without the broker's users. Broker containers now run as the fixed node name rabbit@localhost. At startup, each broker that was RUNNING or still starting goes back to CREATION_IN_PROGRESS, and its container starts in the background. A container that outlived Floci is kept when it still answers. Otherwise the broker gets a new container on its volume, without seeding the admin user, whose password is never stored, and on the host ports it had when they are free. The readiness poller reports it RUNNING once the console it probed answers. A broker from before fixed node names with no surviving container is reported CREATION_FAILED. One whose restore fails is reported CREATION_FAILED and tried again at the next start, one CreateBroker failed for is left as it is, and one a crash left DELETION_IN_PROGRESS is deleted. Part of #5664.
114 lines
6.6 KiB
Markdown
114 lines
6.6 KiB
Markdown
# 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.
|
||
|
||
Brokers are Regional, as on AWS: a broker is listed, described, rebooted and deleted only in the
|
||
Region it was created in. Its name is unique in the account, across its Regions, so `CreateBroker`
|
||
refuses a name another Region of the account already uses with a `ConflictException`.
|
||
|
||
## Supported Actions
|
||
|
||
| Action | Description |
|
||
|---|---|
|
||
| `CreateBroker` | Provisions a RabbitMQ container and seeds the admin user |
|
||
| `DescribeBroker` | Get broker metadata, state, and connection endpoints; echoes the `CreateBroker` settings (security groups, subnets, maintenance window, storage type, authentication strategy, encryption options, and the configuration as `Configurations.Current`), and logs as a `LogsSummary` with the general log group |
|
||
| `ListBrokers` | List all emulated brokers |
|
||
| `DeleteBroker` | Stops and removes the RabbitMQ container |
|
||
| `RebootBroker` | Reboots the broker |
|
||
| `DescribeSharedResources` | Returns an empty `sharedResources` list for an existing broker (always empty, since Floci has no `UpdateBroker` to associate a resource share with 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 |
|
||
| `FLOCI_SERVICES_AMAZONMQ_AMQP_HOST_PORT_BASE` | `5672` | First host port in the range the AMQP listener (5672) is published on |
|
||
| `FLOCI_SERVICES_AMAZONMQ_AMQP_HOST_PORT_MAX` | `5699` | Last host port in the AMQP range |
|
||
| `FLOCI_SERVICES_AMAZONMQ_CONSOLE_HOST_PORT_BASE` | `15672` | First host port in the range the management console (15672) is published on |
|
||
| `FLOCI_SERVICES_AMAZONMQ_CONSOLE_HOST_PORT_MAX` | `15699` | Last host port in the console range |
|
||
|
||
## 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](../configuration/docker.md).
|
||
|
||
- **Port Mapping**: The AMQP port (5672) and the management UI (15672) are each bound
|
||
directly on the Docker host to the next free port in their configured ranges
|
||
(`5672–5699` and `15672–15699` by default), so the first broker is normally reachable
|
||
at `amqp://localhost:5672` and `http://localhost:15672`. This binding is made whether
|
||
Floci runs natively or inside Docker: no Floci-internal proxy fronts the broker, so it is
|
||
the only way a client on the host can reach a broker started by a containerized Floci
|
||
(no `ports:` entry on the `floci` service is needed, or should be added, for these ranges).
|
||
`DescribeBroker` reports the address Floci itself uses: `localhost:<hostPort>` when Floci
|
||
runs natively, or the broker container's Docker-network IP when Floci runs inside Docker.
|
||
In that second case, use `docker ps` to see the host port a given broker container is
|
||
published on.
|
||
- **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.
|
||
- **Restarts**: Floci removes broker containers when it shuts down. With persistent storage,
|
||
each broker that was `RUNNING`, or still starting, goes back to `CREATION_IN_PROGRESS` when
|
||
Floci starts again, and its container starts in the background, so Floci reports itself
|
||
ready without waiting for it. A container that outlived Floci, as when Floci is killed
|
||
rather than shut down, is kept when it still answers. Otherwise the broker gets a new
|
||
container on its volume, published on the host ports it had when they are still free, and
|
||
turns `RUNNING` once the management API answers. Broker containers run as the fixed
|
||
RabbitMQ node name `rabbit@localhost`, which names the node's data directory, so the new
|
||
container keeps the broker's users, vhosts and messages. The admin password Floci never
|
||
stores isn't needed. A broker whose container can't be started is reported
|
||
`CREATION_FAILED` and tried again the next time Floci starts. A broker created before node
|
||
names were fixed kept its data under its old container's hostname, which no new container
|
||
can find, so with no surviving container it is reported `CREATION_FAILED`; delete and
|
||
create it again. A broker `CreateBroker` failed for stays as it is, and one a crash left
|
||
`DELETION_IN_PROGRESS` is deleted with its container and volume.
|
||
|
||
## Examples
|
||
|
||
```bash
|
||
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
|
||
```
|