RabbitMQ
This page covers queue splitting for RabbitMQ. For the general concepts and the message filter reference shared by all queue services, see the Queue Splitting overview.
Queue splitting via MirrordSplitConfig requires mirrord operator 3.170.0 or later and mirrord CLI 3.221.0 or later.
⚠️ Deprecated CRD
MirrordWorkloadQueueRegistry is deprecated and replaced by MirrordSplitConfig. Existing resources continue to work for backward compatibility, but we recommend migrating to MirrordSplitConfig. See Migrating to MirrordSplitConfig.
How It Works
First, we have a consumer app reading messages from a RabbitMQ queue:
When the first mirrord RabbitMQ splitting session starts, two temporary queues are created (one for the target deployed in the cluster, one for the user's local application), and the mirrord operator routes messages according to the user's filter:
If a second user then starts a mirrord RabbitMQ splitting session on the same queue, a third temporary queue is created (for the second user's local application). The mirrord operator includes the new queue and the second user's filter in the routing logic.
If the filters defined by the two users both match some message, one of the users will receive the messages at random.
Enabling RabbitMQ Splitting in Your Cluster
Enable RabbitMQ splitting in the Helm chart
Enable the operator.rmqSplitting setting in the mirrord-operator Helm chart.
Cluster Declaration
The mirrord operator needs a way to connect to your RabbitMQ cluster to consume and re-route messages according to filters. As part of operator installation with operator.rmqSplitting enabled, a new CustomResource type is defined in your cluster — MirrordPropertyList. Use this resource to define the cluster and queue connection parameters for splitting. A MirrordPropertyList must live in the same namespace as the consumer workload (and the MirrordSplitConfig), which may very well be different than your RabbitMQ broker's namespace. MirrordPropertyList is modeled after the env and envFrom fields in a pod's container spec. You can:
Set values directly in the
propertiesfield usingvalue.Reference a single key from a ConfigMap or Secret using
valueFrom.configMapKeyReforvalueFrom.secretKeyRef.Include all keys from a ConfigMap or Secret using
configMapReforsecretRefunderpropertiesFrom. An optionalprefixis prepended to each key.
If you set properties field using value then it must always be string value: '1' instead of value: 1.
You must create at least one MirrordPropertyList with your cluster properties inside of it.
If your application expects specific queue attributes (e.g. durable, or arguments like x-queue-type), create a MirrordPropertyList with those queue declaration properties.
Cluster Properties
url
Full AMQP connection URL (e.g. amqp://user:pass@host:5672/vhost), used as an alternative to host. Any explicitly set scheme, port, username, password, or vhost overrides the corresponding part parsed from the URL
✓ ¹
string (URI)
scheme
Protocol used for the connection
amqp or amqps
amqp
host
Hostname or IP address of the message broker
✓ ¹
string
port
Network port the broker is listening on
integer
5671 or 5672 according to scheme
username
Credential used to authenticate the connection
string
password
Secret key or password for the specified user
string
vhost
A logical isolation unit (virtual host) within the broker
string
'/'
sasl.mechanism
Authentication strategy used during the handshake
amqplain anonymous external plain or rabbit-cr-demo
tls.crt
public certificate (PEM format) used for client authentication
string (PEM)
tls.key
private key (PEM format) matching the client certificate
string (PEM)
ca-certificates.crt
CA certificate(s) (PEM format) used to verify the broker's identity
string (PEM)
client.*
Custom metadata or properties sent to the broker
object / key-value pairs
¹ Provide either url or host. Whenever a part is both present in the url and set as its own property, the individual property wins. A username and password are always required - set them directly or include them in the url.
Queue Declare Properties
durable
If true, the queue survives a broker restart
boolean
false
exclusive
If true, the queue can only be accessed by the current connection and will be deleted when that connection closes
boolean
false
auto_delete
If true, the queue is deleted automatically when the last consumer unsubscribes
boolean
false
arguments.*
Custom properties sent in queue declaration
object / key-value pairs
Provide application context
On operator installation with operator.rmqSplitting enabled, a new CustomResource type is defined in your cluster — MirrordSplitConfig. Users with permissions to get CRDs can verify its existence with kubectl get crd mirrordsplitconfigs.queues.mirrord.metalbear.co. Before you can run sessions with RabbitMQ splitting, you must create a MirrordSplitConfig for the desired target. This tells the operator which queues to split and how the application discovers their names.
See an example MirrordSplitConfig defined for a deployment meme-app living in namespace meme:
The MirrordSplitConfig above says that:
It targets container
mainrunning in deploymentmeme-appin namespacememe.The cluster connection parameters are defined in the
meme-rmq-clusterMirrordPropertyList, which must live in the same namespace as this config (meme).The container consumes two RabbitMQ queues. Their names are read from environment variables
INCOMING_MEME_QUEUE_NAMEandAD_QUEUE_NAME.The queues can be referenced in a mirrord config under IDs
meme-queueandad-queue, respectively.
Link the config to the deployed consumer
The MirrordSplitConfig is a namespaced resource, so it can only reference a consumer deployed in the same namespace. The target workload reference is specified with spec.targetRef:
apiVersion— API version of the Kubernetes workload (e.g.apps/v1, orargoproj.io/v1alpha1for rollouts).kind— type of the workload. Supported:Deployment,StatefulSet,Rollout.name— name of the workload.
Describe consumed queues
Each entry in the spec.queues list describes one or more RabbitMQ queues consumed by the workload:
id— arbitrary queue ID that developers reference from their mirrord config.kind— must bermq.clientConfig(required for RabbitMQ) — name of theMirrordPropertyListcontaining connection properties for the RabbitMQ cluster.queueConfig(optional) — name of aMirrordPropertyListthat contains queue declaration properties (durable, queue type, or any other attribute) for the temporary queues.appConfig.queue— how the application discovers the queue name. Each entry can use:env— exact environment variable name containing the queue name.envLike— regex matching environment variable names.fallback— fallback queue name if the variable is not found. The env var is still rewritten to point at the temporary queue.valueSelector— a jq expression to extract the queue name from the variable's value. Useful when the env var holds JSON rather than a plain name.valuePattern— a regex used when the queue name is embedded in a larger string. The capture group (namedvalue, otherwise the first group) marks the part that is the name; only that part is swapped for the temporary queue and the surrounding text is kept as-is.containers— limit to specific containers (optional, defaults to all non-infra containers).
appConfig.exchange(optional) — when the application reads an exchange name from the environment, the operator injects a dummy exchange name there so the local app does not publish to or bind against the real exchange. Uses the same structure asappConfig.queue.
The mirrord operator can only read consumer's environment variables if they are either:
defined directly in the workload's pod template, with the value defined in
valueor invalueFromvia config map reference; orloaded from config maps using
envFrom.
Drain timeout
After the last session against a target ends, the operator keeps the split's temporary resources alive for the drain timeout so a new session can reuse them, then tears them down. It does not wait for unread messages to be consumed first.
spec.drainTimeout on the MirrordSplitConfig
seconds
One split
Wins over the cluster-wide default.
drainTimeout
Behavior
unset (both)
Tear down as soon as the last session ends (same as 0).
0
Tear down immediately. Unread messages may be lost.
N
Keep resources for up to N seconds, then tear down.
Setting a filter
For the full filter reference (queue_type, message_filter, jq_filter), see the overview. RabbitMQ uses queue_type: RMQ and supports message_filter on message headers.
In the example above, the local application will receive a subset of messages from the RabbitMQ queue described in the MirrordSplitConfig under ID meme-queue. All received messages will have a message header baggage containing mirrord-session=alice.
Last updated
Was this helpful?

