floci-io/floci · error · AwsException
ConflictException
ConflictException
Error message
Broker already exists: " + name
What it means
Floci keeps a per-instance registry of brokers and rejects CreateBroker when an existing broker already has the same BrokerName, returning 409 ConflictException. Broker names are unique per emulator state (unlike AWS where uniqueness is account+region scoped but effectively the same locally).
Source
Thrown at src/main/java/io/github/hectorvent/floci/services/amazonmq/AmazonMqService.java:99
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);
}
MqUser admin = requestedUsers.get(0);
if (admin.getUsername() == null || admin.getUsername().isBlank()) {
throw new AwsException("BadRequestException", "Broker user username is required", 400);
}
validateUserPassword(admin.getPassword());
if (storage.scan(k -> true).stream().anyMatch(b -> name.equals(b.getBrokerName()))) {
throw new AwsException("ConflictException", "Broker already exists: " + name, 409);
}
String brokerId = "b-" + UUID.randomUUID();
String accountId = regionResolver.getAccountId();
String brokerArn = AwsArnUtils.Arn.of("mq", config.defaultRegion(), accountId,
"broker:" + name + ":" + brokerId).toString();
String engineVersion = (params.engineVersion() == null || params.engineVersion().isBlank())
? DEFAULT_ENGINE_VERSION : params.engineVersion();
Broker broker = new Broker(brokerId, brokerArn, name, ENGINE_RABBITMQ,
engineVersion, deploymentMode, params.hostInstanceType());
broker.setAccountId(accountId);
broker.setVolumeId(String.format("%06x", new SecureRandom().nextInt(0xFFFFFF)));
broker.setPubliclyAccessible(params.publiclyAccessible());
broker.setAutoMinorVersionUpgrade(params.autoMinorVersionUpgrade());
if (params.users() != null) {
broker.setUsers(new ArrayList<>(params.users()));
}View on GitHub (pinned to 62ff490619)
Solutions
- Delete the existing broker first: aws mq delete-broker --broker-id <id>, wait for it to disappear, then recreate
- Use a unique broker name per test run (e.g. suffix with a UUID or timestamp)
- If persistent storage holds stale brokers from earlier runs, clean the storage path or list-and-delete existing brokers in test setup
Example fix
# before aws mq create-broker --broker-name demo ... # second run -> ConflictException # after aws mq delete-broker --broker-id b-xxxx || true aws mq create-broker --broker-name demo ...
Defensive patterns
Strategy: try-catch
Validate before calling
boolean nameTaken = mqClient.listBrokers().brokers().stream()
.anyMatch(b -> name.equals(b.brokerName()));
if (nameTaken) throw new IllegalStateException("Broker name already in use: " + name); Try / catch
try {
mqClient.createBroker(req);
} catch (ConflictException e) {
// idempotent create: treat existing broker as success, or delete-and-retry once
String id = findBrokerIdByName(name);
if (id == null) throw e;
mqClient.deleteBroker(r -> r.brokerId(id));
mqClient.createBroker(req);
} Prevention
- Use unique broker names per test run (name + UUID suffix)
- Clean up brokers in @AfterEach to avoid leaking state into the next run
When it happens
Trigger: Running CreateBroker twice with the same BrokerName without an intervening DeleteBroker; re-running a test script or integration suite against a persistent/hybrid storage mode that retained the previous broker.
Common situations: Test suites that create named brokers and fail before cleanup; switching storage to persistent mode so brokers survive restarts while the setup code assumes a clean slate; retries of a create call that actually succeeded server-side.
Related errors
- BadRequestException
- ServiceAlreadyExists
- TrailAlreadyExistsException
- ResourceAlreadyExistsException
- ResourceInUseException
AI-assisted analysis of floci-io/floci@62ff490619 (2026-08-14).
Data as JSON: /api/errors/105fb47dd7fce2fb.
Report an issue: GitHub.