{"record":{"id":"f98240759d6436d1","repo":"nautechsystems/nautilus_trader","slug":"external-message-bus-factory-cannot-be-combined-wi-f98240","errorCode":null,"errorMessage":"external message bus factory cannot be combined with injected egress","messagePattern":"external message bus factory cannot be combined with injected egress","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/system/src/builder.rs","lineNumber":337,"sourceCode":"\n    /// Build and inject external message bus egress from a factory.\n    #[must_use]\n    pub fn with_external_msgbus_factory(\n        mut self,\n        factory: Box<dyn MessageBusBackingFactory>,\n    ) -> Self {\n        self.external_msgbus_factory = Some(factory);\n        self\n    }\n\n    /// Build the [`NautilusKernel`] with the configured settings.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if kernel initialization fails.\n    pub fn build(self) -> anyhow::Result<NautilusKernel> {\n        if self.external_msgbus_factory.is_some() && self.external_msgbus_egress.is_some() {\n            anyhow::bail!(\"external message bus factory cannot be combined with injected egress\");\n        }\n\n        if self.external_msgbus_factory.is_some()\n            && self\n                .msgbus\n                .as_ref()\n                .and_then(|config| config.external_streams.as_ref())\n                .is_some_and(|streams| !streams.is_empty())\n        {\n            anyhow::bail!(\n                \"NautilusKernelBuilder cannot consume external message bus streams; \\\n                 use LiveNodeBuilder::with_external_msgbus_factory for ingress\"\n            );\n        }\n\n        let config = KernelConfig {\n            environment: self.environment,\n            trader_id: self.trader_id,","sourceCodeStart":319,"sourceCodeEnd":355,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/system/src/builder.rs#L319-L355","documentation":"NautilusKernelBuilder::build refuses a configuration that sets both an external message bus factory and injected external msgbus egress. These are two alternative mechanisms for integrating an external message bus, and combining them is ambiguous, so the builder fails fast at build time. It is a configuration-conflict check, not a runtime fault.","triggerScenarios":"Calling NautilusKernelBuilder::with_external_msgbus_factory(...) and also providing external_msgbus_egress(...) on the same builder, then calling build().","commonSituations":"Copy-pasting wiring code from a LiveNodeBuilder example (which uses the factory) into a kernel builder that already injects egress; refactoring the bus integration and leaving both hooks set.","solutions":["Remove one of the two calls: keep the injected egress if you want direct message forwarding, or keep the factory if you want the external bus to be constructed by the factory","Use LiveNodeBuilder::with_external_msgbus_factory instead if the external bus owns both ingress and egress","Decide the integration style explicitly and set only the corresponding builder option"],"exampleFix":"// before\nlet kernel = NautilusKernelBuilder::new(config)\n    .with_external_msgbus_factory(factory)\n    .with_external_msgbus_egress(egress)\n    .build()?;\n// after\nlet kernel = NautilusKernelBuilder::new(config)\n    .with_external_msgbus_egress(egress)\n    .build()?;","handlingStrategy":"validation","validationCode":"// Before build(): assert only one external-bus integration is configured\ndebug_assert!(\n    !(cfg.external_msgbus_factory.is_some() && cfg.external_msgbus_egress.is_some()),\n    \"choose either external msgbus factory or injected egress, not both\"\n);","typeGuard":null,"tryCatchPattern":"match builder.build() {\n    Err(e) if e.to_string().contains(\"cannot be combined with injected egress\") => {\n        // strip one of the two options and rebuild\n    }\n    other => other?,\n}","preventionTips":["Pick one external-bus integration pattern per deployment and document it","Centralize builder wiring in one constructor function","Review builder chains for duplicated bus options during refactors"],"tags":["rust","builder","config","message-bus"],"backgroundTag":"mutually-exclusive-options","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}