{"record":{"id":"a18c242b2f4089a2","repo":"MassTransit/MassTransit","slug":"only-a-single-consumer-can-be-connected-to-a-queue-name","errorCode":null,"errorMessage":"Only a single consumer can be connected to a queue: {Name}","messagePattern":"Only a single consumer can be connected to a queue: (.+?)","errorType":"validation","errorClass":"ConfigurationException","httpStatus":null,"severity":"error","filePath":"src/MassTransit/Transports/Fabric/MessageQueue.cs","lineNumber":57,"sourceCode":"\n            _dispatcher = Task.Run(() => StartDispatcher());\n        }\n\n        public string Name { get; }\n\n        public TopologyHandle ConnectMessageReceiver(TContext nodeContext, IMessageReceiver<T> receiver)\n        {\n            try\n            {\n                var handle = _receivers.Connect(receiver);\n\n                handle = _observer.ConsumerConnected(nodeContext, handle, Name);\n\n                return handle;\n            }\n            catch (Exception exception)\n            {\n                throw new ConfigurationException($\"Only a single consumer can be connected to a queue: {Name}\", exception);\n            }\n        }\n\n        public async Task Deliver(DeliveryContext<T> context)\n        {\n            if (context.WasAlreadyDelivered(this))\n                return;\n\n            if (context.EnqueueTime.HasValue)\n                DeliverWithDelay(context);\n            else\n            {\n                await _channel.Writer.WriteAsync(context, context.CancellationToken).ConfigureAwait(false);\n\n                _metrics.MessageCount.Add();\n            }\n        }\n","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/MassTransit/MassTransit/blob/62ab339afa3bac2e9b3fe1769d0d35d7e44778e9/src/MassTransit/Transports/Fabric/MessageQueue.cs#L39-L75","documentation":"MessageQueue.ConnectMessageReceiver attaches a consumer to an in-memory transport queue node. The in-memory fabric models a queue as point-to-point: only one receiver may be bound at a time. When a second consumer (receiver) attempts to connect while one is already registered, the observer/callback connection fails and is rethrown as a ConfigurationException naming the queue — a transport-topology misconfiguration, not a transient fault.","triggerScenarios":"Calling ConnectMessageReceiver on a MessageQueue that already has an active receiver, or when the internal connect callback throws for the queue.","commonSituations":"Two receive endpoints in bus configuration resolving to the same queue name; restarting a receiver without disconnecting the old handle; accidental duplicate endpoint definitions.","solutions":["Give each consumer a unique queue name so each queue has exactly one consumer","Disconnect the existing receiver (dispose the handle) before connecting a new one","Check endpoint configuration for duplicate queue names"],"exampleFix":"// before\n// two endpoints both using queue \"orders\"\n// after\ncfg.ReceiveEndpoint(\"orders\", e => e.Consumer<OrdersConsumer>());\ncfg.ReceiveEndpoint(\"orders-retry\", e => e.Consumer<OrdersRetryConsumer>());","handlingStrategy":"try-catch","validationCode":"if (queue.IsConnected)\n    throw new InvalidOperationException($\"Queue {queue.Name} already has a consumer\");","typeGuard":null,"tryCatchPattern":"try\n{\n    handle = queue.ConnectMessageReceiver(receiver);\n}\ncatch (ConfigurationException ex) when (ex.Message.Contains(\"single consumer\"))\n{\n    // disconnect existing receiver first, then retry\n}","preventionTips":["Use unique queue names per consumer endpoint","Always dispose previous receive handles before reconnecting","Audit receive endpoint configuration for duplicate queue names"],"tags":["messaging","queue","consumer"],"backgroundTag":"invalid-state-transition","analyzedSha":"62ab339afa3bac2e9b3fe1769d0d35d7e44778e9","analyzedAt":"2026-09-13T22:47:47.593Z","contentChangedAt":"2026-09-13T22:47:47.593Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}