Follow WebhooksHandler to another Broker only once the current one is drained

WebhooksHandler publishes GitHub Events through one of several free-tier CloudAMQP Brokers and rotates to the next one on its own when the current one reaches its monthly message limit (its ADR-0003). This app configures the same Brokers ($rabbitMqConnectionStrings) but reads exactly one, chosen by the broker.active_index Setting, and until now only the Operator could change it (POST /api/v1/broker/switch/{index}). After an automatic rotation, new Events piled up on the new Broker while every Worker kept waiting on the old, silent one — for as long as it took someone to notice.

The producer now tells this app where it went (its ADR-0005: POST /api/v1/broker/pending-switch, the target named by host and virtual host), and this app moves on its own. Two things shaped how:

Two corners of the drain are worth spelling out:

The Operator’s hand still wins: POST /api/v1/broker/switch/{index} moves immediately and drops any Pending Switch, and DELETE /api/v1/broker/pending-switch cancels one without moving. A notification whose switchedAt is older than the Pending Switch already on record is ignored, so late or out-of-order deliveries from the producer’s retry queue cannot move the Broker backwards.

Consequences