{"record":{"id":"017af4a87e7a7829","repo":"alibaba/canal","slug":"start-rabbitmq-producer-error-017af4","errorCode":null,"errorMessage":"Start RabbitMQ producer error","messagePattern":"Start RabbitMQ producer error","errorType":"exception","errorClass":"CanalClientException","httpStatus":null,"severity":"error","filePath":"connector/rabbitmq-connector/src/main/java/com/alibaba/otter/canal/connector/rabbitmq/consumer/CanalRabbitMQConsumer.java","lineNumber":106,"sourceCode":"            factory.setPassword(password);\n        }\n        // 解析出端口 modified by 16075140\n        if (nameServer != null && nameServer.contains(\":\")) {\n            String[] serverHostAndPort = AddressUtils.splitIPAndPort(nameServer);\n            factory.setHost(serverHostAndPort[0]);\n            factory.setPort(Integer.parseInt(serverHostAndPort[1]));\n        } else {\n            factory.setHost(nameServer);\n        }\n\n        factory.setAutomaticRecoveryEnabled(true);\n        factory.setNetworkRecoveryInterval(5000);\n        factory.setVirtualHost(vhost);\n        try {\n            connect = factory.newConnection();\n            channel = connect.createChannel();\n        } catch (IOException | TimeoutException e) {\n            throw new CanalClientException(\"Start RabbitMQ producer error\", e);\n        }\n\n        // 不存在连接 则重新连接\n        if (connect == null) {\n            this.connect();\n        }\n\n        Consumer consumer = new DefaultConsumer(channel) {\n\n            @Override\n            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties,\n                                       byte[] body) throws IOException {\n\n                if (body != null) {\n                    channel.basicAck(envelope.getDeliveryTag(), process(body));\n                }\n            }\n        };","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/alibaba/canal/blob/87be50e87686a3e8af08c368d0e1ffd1f59eb04a/connector/rabbitmq-connector/src/main/java/com/alibaba/otter/canal/connector/rabbitmq/consumer/CanalRabbitMQConsumer.java#L88-L124","documentation":"Thrown by CanalRabbitMQConsumer.connect (the message says 'producer' but this is the consumer) when ConnectionFactory.newConnection() or createChannel() throws IOException or TimeoutException. The RabbitMQ broker could not be reached, refused the connection, or did not respond in time.","triggerScenarios":"factory.newConnection() / connect.createChannel() at lines 100-101 fail. Causes: wrong host/port; RabbitMQ broker down; auth credentials rejected; virtual host does not exist; firewall blocking the AMQP port; broker too slow to complete the handshake (TimeoutException).","commonSituations":"Misconfigured rabbitmq.host or rabbitmq.virtual.host; broker restart during consumer startup; wrong credentials; AMQP port (5672) blocked by a firewall/security group; high broker load causing handshake timeout.","solutions":["Verify rabbitmq.host/rabbitmq.port point to a reachable broker and that the AMQP port is open.","Confirm credentials and the virtual host are correct and that the user has access to the vhost.","RabbitMQ's factory has automaticRecoveryEnabled=true already set; retry connect() after a brief delay for transient broker outages.","Increase connection timeout if handshakes are slow under load."],"exampleFix":"// before\ntry {\n    connect = factory.newConnection();\n    channel = connect.createChannel();\n} catch (IOException | TimeoutException e) {\n    throw new CanalClientException(\"Start RabbitMQ producer error\", e);\n}\n\n// after — include broker detail and retry transient failures\nfactory.setConnectionTimeout(10000);\nint attempts = 0;\nwhile (attempts++ < 3) {\n    try {\n        connect = factory.newConnection();\n        channel = connect.createChannel();\n        break;\n    } catch (IOException | TimeoutException e) {\n        if (attempts >= 3) throw new CanalClientException(\n            \"Start RabbitMQ consumer error [host=\" + nameServer + \"]: \" + e.getMessage(), e);\n    }\n}","handlingStrategy":"retry","validationCode":"if (StringUtils.isEmpty(nameServer)) throw new IllegalStateException(\"rabbitmq host missing\");\nfactory.setConnectionTimeout(10000);","typeGuard":null,"tryCatchPattern":"int attempts = 0;\nwhile (attempts++ < 3) {\n    try {\n        connect = factory.newConnection();\n        channel = connect.createChannel();\n        break;\n    } catch (IOException | TimeoutException e) {\n        if (attempts >= 3) throw new CanalClientException(\"Start RabbitMQ consumer error\", e);\n    }\n}","preventionTips":["Confirm the broker host/port and AMQP port (5672) are reachable.","Validate credentials and vhost before connecting.","Rely on automaticRecoveryEnabled (already on) and retry transient failures."],"tags":["rabbitmq","network","canal-connector","initialization","timeout"],"backgroundTag":null,"analyzedSha":"87be50e87686a3e8af08c368d0e1ffd1f59eb04a","analyzedAt":"2026-08-14T04:30:11.918Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}