{"record":{"id":"f436290d4be6ac0c","repo":"micro/go-micro","slug":"not-connected-f43629","errorCode":null,"errorMessage":"not connected","messagePattern":"not connected","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"broker/rabbitmq/rabbitmq.go","lineNumber":244,"sourceCode":"\t\tm.Headers[k] = v\n\t}\n\n\tif r.getWithoutExchange() {\n\t\tm.Headers[\"Micro-Topic\"] = topic\n\t}\n\n\tif r.conn == nil {\n\t\treturn errors.New(\"connection is nil\")\n\t}\n\n\treturn r.conn.Publish(r.conn.exchange.Name, topic, m)\n}\n\nfunc (r *rbroker) Subscribe(topic string, handler broker.Handler, opts ...broker.SubscribeOption) (broker.Subscriber, error) {\n\tvar ackSuccess bool\n\n\tif r.conn == nil {\n\t\treturn nil, errors.New(\"not connected\")\n\t}\n\n\topt := broker.SubscribeOptions{\n\t\tAutoAck: true,\n\t}\n\n\tfor _, o := range opts {\n\t\to(&opt)\n\t}\n\n\t// Make sure context is setup\n\tif opt.Context == nil {\n\t\topt.Context = context.Background()\n\t}\n\n\tctx := opt.Context\n\tif subscribeContext, ok := ctx.Value(subscribeContextKey{}).(context.Context); ok && subscribeContext != nil {\n\t\tctx = subscribeContext","sourceCodeStart":226,"sourceCodeEnd":262,"githubUrl":"https://github.com/micro/go-micro/blob/24529f140421a11a33b6999ab7944f2021cfd69c/broker/rabbitmq/rabbitmq.go#L226-L262","documentation":"rbroker.Subscribe requires an established connection; if r.conn is nil it returns \"not connected\" before creating a subscriber. ackSuccess is initialized for the subscribe/ack flow, but without a connection there is nothing to subscribe on.","triggerScenarios":"Calling broker.Subscribe() before broker.Connect(), after Disconnect(), or on a broker instance whose connection was never established.","commonSituations":"Consumers started before the broker connection is ready (startup race); resubscribing after a failure without reconnecting; test setups that instantiate the broker without connecting.","solutions":["Connect first: call broker.Connect() and handle its error before Subscribe.","On reconnect, recreate subscriptions since they are tied to the old connection.","Add a readiness gate (e.g. wait for Connect success) before starting consumers."],"exampleFix":"// before\nsub, err := b.Subscribe(\"events\", handler) // \"not connected\"\n// after\nif err := b.Connect(); err != nil { return err }\nsub, err := b.Subscribe(\"events\", handler)","handlingStrategy":"validation","validationCode":"if err := b.Connect(); err != nil { return err }\n// only now is Subscribe safe","typeGuard":null,"tryCatchPattern":"sub, err := b.Subscribe(topic, handler)\nif err != nil && strings.Contains(err.Error(), \"not connected\") {\n    if cerr := b.Connect(); cerr != nil { return cerr }\n    sub, err = b.Subscribe(topic, handler)\n}","preventionTips":["Start consumers only after broker.Connect returns nil.","Recreate subscriptions after every reconnect.","Add a readiness check/gate before launching subscriber goroutines."],"tags":["rabbitmq","subscribe","not-connected","lifecycle"],"backgroundTag":"not-connected","analyzedSha":"24529f140421a11a33b6999ab7944f2021cfd69c","analyzedAt":"2026-09-01T02:52:24.923Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}