workerman Rabbitmq 是否支持集群配置

wangyw

问题描述

workerman Rabbitmq 是否支持集群配置

目前看配置文件无法设置像phpamqp一样的集群配置

279 1 1
1个回答

walkor

phpamqp 是怎么设置集群的?

  • wangyw 2023-11-01
    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;
    }
  • wangyw 2023-11-01

    创建连接的时候,传一个集群的多维数组

  • walkor 2023-11-01

    他也是连其中一个节点,你可以随机连一个节点,也可以加一个负载均衡,比如nginx

  • wangyw 2023-11-01

    大佬,那就是说workerman-rabbitmq 需要自己加一段随机节点连接嘛?

  • walkor 2023-11-01

    最简单的方案。
    $hosts = ['ip1:port1', 'ip2:port2']; // 多维数组
    $host = $hosts[array_rand($hosts)]; // 随机选其中一个

🔝