floci-io/floci · error · AwsException

BadRequestException

BadRequestException

Error message

BrokerName is required

What it means

AmazonMQ BadRequestException (HTTP 400) thrown by AmazonMqService.createBroker when BrokerName is null or blank. It is the first validation in broker creation, checked before engine type, deployment mode, and users — so a missing name masks later validation errors.

Source

Thrown at src/main/java/io/github/hectorvent/floci/services/amazonmq/AmazonMqService.java:72

    }

    @PostConstruct
    public void init() {
        startReadinessPoller();
    }

    @PreDestroy
    public void shutdown() {
        // Container teardown is wired into EmulatorLifecycle.onStop() via
        // RabbitMqManager.stopAll() (ordered with the other container managers);
        // here we only stop the readiness poller.
        poller.shutdown();
    }

    public Broker createBroker(CreateBrokerParams params) {
        String name = params.brokerName();
        if (name == null || name.isBlank()) {
            throw new AwsException("BadRequestException", "BrokerName is required", 400);
        }
        if (!ENGINE_RABBITMQ.equals(params.engineType())) {
            throw new AwsException("BadRequestException",
                    "Only RABBITMQ EngineType is supported", 400);
        }
        String deploymentMode = params.deploymentMode() == null
                ? DEPLOYMENT_SINGLE_INSTANCE : params.deploymentMode();
        if (!DEPLOYMENT_SINGLE_INSTANCE.equals(deploymentMode)) {
            throw new AwsException("BadRequestException",
                    "Only SINGLE_INSTANCE DeploymentMode is supported", 400);
        }
        // RabbitMQ brokers require exactly one user at creation; that user becomes the
        // broker's RabbitMQ administrator (seeded into the container). This mirrors AWS,
        // which rejects CreateBroker for RabbitMQ unless exactly one user is supplied.
        List<MqUser> requestedUsers = params.users() == null ? List.of() : params.users();
        if (requestedUsers.size() != 1) {
            throw new AwsException("BadRequestException",
                    "Exactly one broker user is required for a RabbitMQ broker", 400);

View on GitHub (pinned to 62ff490619)

Solutions

  1. Set brokerName explicitly and assert it is non-blank before calling createBroker
  2. Check the variable/parameter feeding the name for typos or unset environment values
  3. Remember downstream constraints: this emulator only accepts EngineType=RABBITMQ and DeploymentMode=SINGLE_INSTANCE, so set those too and avoid the next two errors

Example fix

// before
mq.createBroker(r -> r.engineType("RABBITMQ")); // brokerName never set

// after
String name = Objects.requireNonNull(System.getenv("BROKER_NAME"), "demo-broker");
mq.createBroker(r -> r.brokerName(name).engineType("RABBITMQ").deploymentMode("SINGLE_INSTANCE")
    .users(adminUser));
Defensive patterns

Strategy: validation

Validate before calling

if (brokerName == null || brokerName.isBlank()) {
    throw new IllegalArgumentException("BrokerName is required");
}

Type guard

private static boolean isCreatableBrokerRequest(String name, String engine, String mode) {
    return name != null && !name.isBlank()
        && "RABBITMQ".equals(engine)
        && (mode == null || "SINGLE_INSTANCE".equals(mode));
}

Try / catch

try {
    mq.createBroker(r -> r.brokerName(name).engineType("RABBITMQ").deploymentMode("SINGLE_INSTANCE").users(u));
} catch (BadRequestException e) {
    // inspect message: name/engine/mode each have a distinct validation error
}

Prevention

When it happens

Trigger: mq.createBroker with a request whose brokerName is null or whitespace — unset builder field, empty string after templating, or a blank value from config. Fails before the RABBITMQ-only engine check runs.

Common situations: IaC variables for broker name not wired (Terraform var unset → empty); CLI scripts passing $BROKER_NAME unset; request builders shared across services where the name setter was skipped on one path.

Understand the failure class

Background: BadRequestException (HTTP 400) — NestJS 'Bad Request' Errors: Why They Fire and How to Fix Them — this error's family across 4 libraries.

Related errors


AI-assisted analysis of floci-io/floci@62ff490619 (2026-08-14). Data as JSON: /api/errors/fcf2ba59b25ec5b4. Report an issue: GitHub.