workerman Rabbitmq 是否支持集群配置
目前看配置文件無法設置像phpamqp一樣的集群配置
phpamqp 是怎么設置集群的?
public static function create_connection($hosts, $options = array())
{
if (!is_array($hosts) || count($hosts) < 1) {
throw new \InvalidArgumentException(
'An array of hosts are required when attempting to create a connection'
);
}
foreach ($hosts as $hostdef) {
self::validate_host($hostdef);
$host = $hostdef['host'];
$port = $hostdef['port'];
$user = $hostdef['user'];
$password = $hostdef['password'];
$vhost = isset($hostdef['vhost']) ? $hostdef['vhost'] : '/';
try {
$conn = static::try_create_connection($host, $port, $user, $password, $vhost, $options);
return $conn;
} catch (\Exception $e) {
$latest_exception = $e;
}
}
throw $latest_exception;
}
最簡單的方案。
$hosts = ['ip1:port1', 'ip2:port2']; // 多維數(shù)組
$host = $hosts[array_rand($hosts)]; // 隨機選其中一個