Guide · Amazon MQ · High Availability
Amazon MQ Active/Standby HA for MCP Servers — Failover URIs, RabbitMQ Cluster Reconnection, and In-Flight Message Safety
Amazon MQ offers two high-availability deployment modes: ActiveMQ active/standby (two nodes sharing storage, automatic failover) and RabbitMQ cluster (three nodes with quorum replication). Both modes protect against single-node failure, but they have different failover mechanics that your MCP server client code must handle correctly. This guide covers the HA deployment options, the specific client configuration needed for each engine, in-flight message safety during failover, and the operational procedures for planned maintenance failovers.
TL;DR
For ActiveMQ active/standby: use a failover://(ssl://primary-host:61617,ssl://standby-host:61617)?randomize=false transport URI with the OpenWire client; the client detects the dropped connection and transparently reconnects to the standby. For STOMP, there is no native failover transport — implement reconnection with exponential backoff using stompit.ConnectFailover. For RabbitMQ cluster: pass a list of AMQP URIs to amqp.connect() in amqp-connection-manager — the manager cycles through nodes on connection failure. Enable quorum queues (x-queue-type: quorum) so queue state survives node loss. In both cases, messages sent without publisher confirms during the failover window may be lost — always use publisher confirms for critical task dispatch. For broker setup, see the Amazon MQ overview.
ActiveMQ active/standby deployment mode
Amazon MQ's ActiveMQ ACTIVE_STANDBY_MULTI_AZ deployment creates two broker nodes in different availability zones. The active node handles all connections and writes. The standby node stays in sync via a shared Amazon EFS filesystem. When the active node fails (or is manually failed over), Amazon MQ promotes the standby node — the failover typically completes in under 60 seconds.
Both nodes are always present in the broker description. Use DescribeBrokerCommand to retrieve both endpoints:
import { MqClient, DescribeBrokerCommand } from "@aws-sdk/client-mq";
async function getActiveMQEndpoints(brokerId: string) {
const mq = new MqClient({ region: process.env.AWS_REGION });
const broker = await mq.send(new DescribeBrokerCommand({ BrokerId: brokerId }));
if (broker.BrokerState !== "RUNNING") {
throw new Error(`Broker ${brokerId} not running: ${broker.BrokerState}`);
}
// For ACTIVE_STANDBY_MULTI_AZ, there are two instances
const openWireEndpoints = broker.BrokerInstances
.flatMap(i => i.Endpoints)
.filter(e => e.includes(":61617")); // OpenWire TLS port
const stompEndpoints = broker.BrokerInstances
.flatMap(i => i.Endpoints)
.filter(e => e.includes(":61614")); // STOMP TLS port
return { openWireEndpoints, stompEndpoints };
}
const { openWireEndpoints, stompEndpoints } = await getActiveMQEndpoints(process.env.BROKER_ID);
// openWireEndpoints: ["ssl://b-abc.mq.us-east-1a.amazonaws.com:61617", "ssl://b-abc.mq.us-east-1b.amazonaws.com:61617"]
The active/standby architecture means exactly one node accepts connections at any time. Connecting to the standby address results in a refused connection — the standby only starts accepting connections after failover. This is why client-side failover is essential: on a primary failure, the client must try the standby address.
STOMP failover with stompit.ConnectFailover
The stompit package includes ConnectFailover, which accepts multiple server configurations and cycles through them on connection failure. This is the STOMP equivalent of ActiveMQ's OpenWire failover transport:
import stompit from "stompit";
function createFailoverConnection(
primaryHost: string,
standbyHost: string,
username: string,
password: string
): stompit.ConnectFailover {
const serverConfigs = [
{
host: primaryHost,
port: 61614,
ssl: true,
connectHeaders: {
host: "/",
login: username,
passcode: password,
"heart-beat": "10000,10000",
"accept-version": "1.1,1.2"
}
},
{
host: standbyHost,
port: 61614,
ssl: true,
connectHeaders: {
host: "/",
login: username,
passcode: password,
"heart-beat": "10000,10000",
"accept-version": "1.1,1.2"
}
}
];
const failover = new stompit.ConnectFailover(serverConfigs, {
randomize: false, // Try primary first, standby second
initialReconnectDelay: 1000,
maxReconnectDelay: 30000,
useExponentialBackOff: true,
maxReconnects: -1 // Retry indefinitely
});
failover.on("connecting", (connector) => {
console.log(`Connecting to STOMP broker via ${connector.serverProperties.host}`);
});
failover.on("connect", (client) => {
console.log("STOMP failover connected");
});
failover.on("error", (err) => {
console.error("STOMP failover error:", err.message);
});
return failover;
}
// Use with stompit.Channel for automatic reconnect and message replay
const failoverConnection = createFailoverConnection(
primaryHost, standbyHost, username, password
);
const channel = stompit.createChannel(failoverConnection);
// Subscriptions are automatically re-established after failover reconnect
channel.subscribe(
{ destination: "/queue/mcp.tasks", ack: "client-individual" },
async (err, message) => {
if (err) {
console.error("STOMP subscribe error:", err.message);
return;
}
// Process message normally — stompit handles reconnect transparently
const body = await readMessage(message);
await processTask(JSON.parse(body));
message.ack();
}
);
During a failover event, messages that have been received but not yet acknowledged will be redelivered after the reconnection — this is the STOMP protocol's guarantee. Your consumer code must be idempotent: if processTask can be called twice for the same message without causing duplicate side effects, your system is safe. Use the message message-id header for idempotency checking if the underlying operation is not naturally idempotent.
RabbitMQ cluster multi-AZ configuration
Amazon MQ's RabbitMQ CLUSTER_MULTI_AZ deployment creates three broker nodes across three availability zones. Unlike ActiveMQ active/standby, all three RabbitMQ nodes are active simultaneously — each accepts connections and handles message routing. Quorum queues replicate message storage across a quorum of nodes (at least 2 of 3), so the cluster tolerates one node failure without data loss.
The CLUSTER_MULTI_AZ RabbitMQ deployment returns a single cluster endpoint (a load-balanced hostname that routes to healthy nodes) in DescribeBrokerCommand. This endpoint stays available during single-node failures:
import { MqClient, DescribeBrokerCommand } from "@aws-sdk/client-mq";
async function getRabbitMQClusterEndpoint(brokerId: string): Promise {
const mq = new MqClient({ region: process.env.AWS_REGION });
const broker = await mq.send(new DescribeBrokerCommand({ BrokerId: brokerId }));
// RabbitMQ cluster returns one AMQPS endpoint that load-balances across nodes
const amqpsEndpoint = broker.BrokerInstances
.flatMap(i => i.Endpoints)
.find(e => e.startsWith("amqps://"));
if (!amqpsEndpoint) throw new Error("No AMQPS endpoint found");
return amqpsEndpoint;
}
For the application client, use amqp-connection-manager with the cluster endpoint. If you have direct access to individual node endpoints (for testing), you can pass multiple URLs — the connection manager cycles through them:
import amqp from "amqp-connection-manager";
// Single cluster endpoint (recommended for Amazon MQ cluster deployments)
const connection = amqp.connect(["amqps://user:pass@cluster.mq.us-east-1.amazonaws.com:5671"], {
reconnectTimeInSeconds: 5,
heartbeatIntervalInSeconds: 10
});
// amqp-connection-manager automatically reconnects and re-runs channelWrapper setup
// on any connection interruption — node failure, maintenance window, network blip
connection.on("connect", ({ url }) => console.log(`Connected: ${url}`));
connection.on("disconnect", ({ err }) => console.error(`Disconnected: ${err?.message}`));
const channelWrapper = connection.createChannel({
json: false,
setup: async (channel) => {
// Channel setup runs on every connect/reconnect
await channel.assertExchange("mcp.tasks", "direct", { durable: true });
await channel.assertQueue("mcp.tasks.reports", {
durable: true,
arguments: {
"x-queue-type": "quorum", // Cluster-durable queue
"x-dead-letter-exchange": "mcp.dlx",
"x-delivery-limit": 3
}
});
await channel.bindQueue("mcp.tasks.reports", "mcp.tasks", "generate_report");
await channel.confirmSelect();
}
});
In-flight message safety during failover
The critical question during broker failover is: what happens to messages that are "in flight" — sent by the producer but not yet acknowledged by a consumer?
For persistent messages sent with publisher confirms: messages confirmed by the broker before the failure are safe — they are on durable storage on the surviving node (RabbitMQ quorum queue) or the shared EFS (ActiveMQ active/standby). Messages sent after the connection drops but before the producer detects the disconnect may be lost if the broker did not confirm them. The producer receives a nack or a connection exception for these; your retry logic should re-publish them.
For unacknowledged consumer messages: messages delivered to consumers but not yet acked are redelivered after failover. The consumer will see the same message again with the redelivered flag set to true. Your consumer must handle this correctly:
channelWrapper.addSetup(async (channel) => {
await channel.prefetch(5);
channel.consume("mcp.tasks.reports", async (msg) => {
if (!msg) return;
const task = JSON.parse(msg.content.toString());
const isRedelivered = msg.fields.redelivered;
if (isRedelivered) {
// Check if this task was already completed (idempotency check)
const alreadyCompleted = await checkTaskCompleted(task.jobId);
if (alreadyCompleted) {
console.log(`Skipping redelivered task ${task.jobId} — already completed`);
channel.ack(msg);
return;
}
}
try {
await processReportTask(task);
await markTaskCompleted(task.jobId); // Record completion for idempotency
channel.ack(msg);
} catch (err) {
channel.nack(msg, false, false); // Send to DLQ after max retries
}
}, { noAck: false });
});
The redelivered flag is set to true for all messages that were previously delivered to a consumer but not acked before the channel or connection closed. During a failover, all in-flight messages (up to your prefetch count) will be redelivered with redelivered: true. The idempotency check prevents duplicate side effects.
Planned maintenance failover procedures
Amazon MQ brokers receive periodic maintenance updates (engine version patches, security updates). Maintenance windows are configurable; during the window, Amazon MQ may restart broker instances. For ACTIVE_STANDBY_MULTI_AZ ActiveMQ, the standby takes over while the active is updated, then the original active becomes standby and receives its update. Total downtime per update is under 60 seconds for most updates.
To minimize impact on MCP server operations during maintenance windows:
import { MqClient, DescribeBrokerCommand } from "@aws-sdk/client-mq";
async function checkBrokerMaintenanceWindow(brokerId: string) {
const mq = new MqClient({ region: process.env.AWS_REGION });
const broker = await mq.send(new DescribeBrokerCommand({ BrokerId: brokerId }));
const { DayOfWeek, TimeOfDay, TimeZone } = broker.MaintenanceWindowStartTime;
const pendingVersion = broker.PendingEngineVersion;
const pendingSecurityGroups = broker.PendingSecurityGroups;
return {
nextMaintenanceWindow: `${DayOfWeek} ${TimeOfDay} ${TimeZone}`,
pendingEngineUpgrade: pendingVersion ?? null,
pendingSecurityGroupChange: pendingSecurityGroups?.length > 0,
brokerState: broker.BrokerState,
// RUNNING, REBOOT_IN_PROGRESS, MAINTENANCE_IN_PROGRESS, etc.
};
}
// Add to MCP server health tool
server.tool(
"get_broker_maintenance_status",
"Check upcoming Amazon MQ broker maintenance windows and pending changes.",
{ brokerId: z.string().describe("Amazon MQ broker ID") },
async ({ brokerId }) => {
const status = await checkBrokerMaintenanceWindow(brokerId);
return {
content: [{ type: "text", text: JSON.stringify(status) }]
};
}
);
For planned failover testing (validating that your MCP server recovers cleanly), you can trigger a manual reboot via the Amazon MQ console or API. Use RebootBrokerCommand to reboot the active node — the standby takes over within the normal failover window, giving you a controlled test of your client's reconnection behavior without waiting for a maintenance event.
Deployment mode comparison
| Attribute | ActiveMQ ACTIVE_STANDBY_MULTI_AZ | RabbitMQ CLUSTER_MULTI_AZ |
|---|---|---|
| Node count | 2 (1 active, 1 standby) | 3 (all active) |
| Failover mechanism | Shared EFS storage, standby promoted on active failure | Quorum replication; surviving majority elects leader |
| Client failover | Must use failover transport URI or ConnectFailover — single endpoint won't reconnect | Cluster endpoint load-balances; amqp-connection-manager handles transparently |
| Failover time | Typically 30–60 seconds | Typically 10–30 seconds (no storage failover needed) |
| Message safety | Persistent messages on shared EFS survive; non-persistent messages may be lost | Quorum queue messages survive any single-node failure; classic queue messages may be lost |
| Throughput during failover | Brief pause while standby becomes active; in-flight messages redelivered | No pause — other nodes continue serving; in-flight messages on failed node requeued |
RabbitMQ CLUSTER_MULTI_AZ provides better failover characteristics — faster failover, no single-connection endpoint dependency, and native quorum replication. Use it for new MCP server deployments. Use ACTIVE_STANDBY_MULTI_AZ ActiveMQ only if your stack requires JMS semantics, STOMP, or MQTT protocols unavailable on RabbitMQ.
Related guides in this arc
- Amazon MQ overview — broker creation, engine choice, IAM permissions, VPC networking, async tool dispatch pattern
- ActiveMQ on Amazon MQ — STOMP client, durable subscribers, virtual topics, dead-letter queue configuration
- RabbitMQ on Amazon MQ — AMQP exchanges, publisher confirms, management API, quorum queue setup
For end-to-end visibility into your MCP server's availability — including tool call latency and uptime through broker failover events — AliveMCP provides monitoring with Slack and email alerting.