AWS中的Symfony RabbitMQ捆绑包(托管服务):有办法让它工作吗?

5lhxktic  于 2022-11-08  发布在  RabbitMQ
关注(0)|答案(2)|浏览(196)

我们真的尝试了很多,但它仍然不能得到Symfony RabbitMQ包(https://github.com/php-amqplib/RabbitMqBundle)运行在AWS(与Docker)。AWS只允许AMQPS和端口5671在AWS管理的服务中打开。
这是我们当前的详细配置:

old_sound_rabbit_mq:
    connections:
        default:
            # nevermind
        secure:
            url: 'amqps://%env(RABBITMQ_USER)%:%env(RABBITMQ_PASSWORD)%@%env(RABBITMQ_HOST)%:%env(RABBITMQ_PORT)%'
            vhost: '%env(RABBITMQ_VHOST)%'
            lazy: true
            connection_timeout: 6
            read_write_timeout: 6
            ssl_context:
                verify_peer: false
            keepalive: true
            heartbeat: 60
            use_socket: true # default false
    producers:
        # use 'old_sound_rabbit_mq.[my-producer-name]_producer' service to send data.
        article_create:
            connection: secure
            exchange_options: { name: pimcore.article.create, type: topic }
            queue_options:
                name: article_create

请注意,我们使用“url”配置值,因为它似乎是为包设置AMQPS的唯一方法。
docker-compose.yml的相关部分:

php-fpm:
        container_name: php-fpm
        environment:
            - RABBITMQ_HOST=my-rabbitmq # usually the docker container (otherwise localhost or server address)
            - RABBITMQ_PORT=5671 # locally it seems to work with 5672
            - RABBITMQ_USER=user
            - RABBITMQ_PASSWORD=password
            - RABBITMQ_VHOST=/
    rabbitmq:
        container_name: my-rabbitmq
        image: rabbitmq:3.8-management
        ports:
            - 127.0.0.1:15672:15672
            - 127.0.0.1:5672:5672
            - 127.0.0.1:5671:5671
        environment:
            - RABBITMQ_DEFAULT_USER=pimcore
            - RABBITMQ_DEFAULT_PASS=pimcore
        volumes:
            - rabbitmq:/var/lib/rabbitmq

以下是从Symfony事件侦听器发送消息的方式:

$this->appKernel->getContainer()->get('old_sound_rabbit_mq.article_create_producer')->publish(
                serialize($objToSend),
                "article_create",
                [
                    'delivery_mode' => AMQPMessage::DELIVERY_MODE_PERSISTENT,
                    'message_id' => md5(uniqid("prefix", true))
                ]
            );

这一切似乎都在本地工作,没有任何问题。在AWS中,我们得到以下错误:

不带插座:

Broken pipe or closed connection

带插座:

[2021-06-08 15:59:45] request.CRITICAL: Uncaught PHP Exception ErrorException: "Warning: socket_recv(): unable to read from socket [104]: Connection reset by peer" at /var/www/vendor/php-amqplib/php-amqplib/PhpAmqpLib/Wire/IO/SocketIO.php line 121 {"exception":"[object] (ErrorException(code: 0): Warning: socket_recv(): unable to read from socket [104]: Connection reset by peer at /var/www/vendor/php-amqplib/php-amqplib/PhpAmqpLib/Wire/IO/SocketIO.php:121)"} []
tsm1rwdh

tsm1rwdh1#

可能会晚,但是。
对于使用Aws MQ(Rabbit)的SSL连接,您需要在路径中添加.perm。
'%env(消息传输DSN)%cacert=%env(解析:消息传输证书)%'
你可以在这个aws网址得到烫发:AmazonRootCA1.pem
希望能帮上忙。

kkbh8khc

kkbh8khc2#

最后解决了-您必须定义一个自定义AMQPChannel,其中包含一个带有SSL选项的自定义AMQPConnection,然后将此AMQPChannel设置为生成器:

// SSL
if ($port === 5671) {
    $sslOptions = array(
        'cafile' => CERTS_PATH . '/ca_certificate.pem',
        'local_cert' => CERTS_PATH . '/client_certificate.pem',
        'local_pk' => CERTS_PATH . '/client_key.pem',
        'verify_peer' => true,
        'verify_peer_name' => false,
    );
    $amqpSslConnection = new AMQPSSLConnection(
        getenv('RABBITMQ_HOST'),
        $port,
        getenv('RABBITMQ_USER'),
        getenv('RABBITMQ_PASSWORD'),
        getenv('RABBITMQ_VHOST'),
        $sslOptions
    );
    $amqpChannel = new AMQPChannel($amqpSslConnection);
    $producer->setChannel($amqpChannel);
    return $producer;
}

相关问题