# AMQP 连接错误：服务器关闭连接 (530) 不允许

- **ID:** `communication/amqp-connection-530-not-allowed`
- **领域:** communication
- **类别:** auth_error
- **错误码:** `530`
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

AMQP 客户端尝试连接时权限不足或虚拟主机（vhost）无效，导致 RabbitMQ 代理拒绝。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| RabbitMQ 3.12.0 | active | — | — |
| pika 1.3.2 | active | — | — |
| amqplib 0.10.3 | active | — | — |

## 解决方案

1. ```
   Verify and grant correct permissions for the user on the target vhost using RabbitMQ CLI: `rabbitmqctl set_permissions -p my_vhost my_user "^.*" "^.*" "^.*"` and ensure the vhost exists with `rabbitmqctl add_vhost my_vhost`.
   ```
2. ```
   Configure the client connection string to explicitly specify the vhost: In Python with pika, use `pika.URLParameters('amqp://user:pass@host:5672/my_vhost')`.
   ```
3. ```
   Check RabbitMQ logs for detailed rejection reason: `tail -f /var/log/rabbitmq/rabbit@host.log` to see if the error is due to vhost mismatch or user permissions.
   ```

## 无效尝试

- **Reinstall RabbitMQ server to reset permissions** — Reinstalling is overkill; the issue is typically a misconfigured vhost or user permissions, not a corrupt installation. (90% 失败率)
- **Use the default guest/guest credentials with default vhost '/'** — RabbitMQ disables guest user access from non-localhost by default; this fails for remote clients. (80% 失败率)
- **Increase the connection timeout in the client** — The error is a rejection, not a timeout; increasing timeout doesn't change permission checks. (95% 失败率)
