我只是在做一个测试,试图让 RabbitMQ 与php-amqplib
. 我刚刚编辑了这个问题,以便它使用正确的端口。对此有什么想法吗?
这是我的PHP文件...
1 #!/usr/bin/env php
2 <?php
3
4 require __DIR__ . '/vendor/autoload.php';
5
6 $dotenv = new Dotenv\Dotenv(__DIR__);
7 $dotenv->load();
8
9 $sample_msg = "0% chance of rain!";
10
11 $amqpConnection = new \PhpAmqpLib\Connection\AMQPStreamConnection(
12 getenv('RABBITMQ_HOST'),
13 getenv('RABBITMQ_PORT'),
14 getenv('RABBITMQ_USER'),
15 getenv('RABBITMQ_PASSWORD'),
16 getenv('RABBITMQ_VHOST')
17 );
18
19 $amqpChannel = $amqpConnection->channel();
20 $amqpChannel->queue_declare(getenv('SFTP_RABBITMQ_QUEUE'), false, true, false, false);
21
22 $msg = new AMQPMessage($sample_msg);
23 $channel->basic_publish($msg, '', 'hello');
24
25 echo " [x] Sent $sample_msg\n";
这是我的 .env ...
RABBITMQ_HOST=dev.website.co.uk
RABBITMQ_PORT=5672 // ammended
RABBITMQ_VHOST=/
RABBITMQ_LOGIN=xxxxxx
RABBITMQ_PASSWORD=xxxxxx
SFTP_RABBITMQ_QUEUE=my_test_queue
这是composer.json ...
{
"name": "neil/sftp-user-create",
"type": "project",
"require": {
"php-amqplib/php-amqplib": "^2.7",
"vlucas/phpdotenv": "^2.4"
},
"license": "proprietary",
"authors": [
{
"name": "Me",
"email": "my@email-address.com"
}
]
}
这是我得到的错误...
PHP Fatal error: Uncaught PhpAmqpLib\Exception\AMQPRuntimeException: Broken pipe or closed connection in /home/neil/PhpstormProjects/sftp-user-create/vendor/php-amqplib/php-amqplib/PhpAmqpLib/Wire/IO/StreamIO.php:214
Stack trace:
#0 /home/neil/PhpstormProjects/sftp-user-create/vendor/php-amqplib/php-amqplib/PhpAmqpLib/Wire/AMQPReader.php(149): PhpAmqpLib\Wire\IO\StreamIO->read(7)
#1 /home/neil/PhpstormProjects/sftp-user-create/vendor/php-amqplib/php-amqplib/PhpAmqpLib/Wire/AMQPReader.php(106): PhpAmqpLib\Wire\AMQPReader->rawread(7)
#2 /home/neil/PhpstormProjects/sftp-user-create/vendor/php-amqplib/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php(522): PhpAmqpLib\Wire\AMQPReader->read(7)
#3 /home/neil/PhpstormProjects/sftp-user-create/vendor/php-amqplib/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php(570): PhpAmqpLib\Connection\AbstractConnection->wait_frame(0)
#4 /home/neil/PhpstormProjects/sftp-user-create/vendor/php-amqplib/php-amqplib/PhpAmqpLib/Channel/AbstractChannel.php(225): PhpAmqpLib\Connection\Abstr in /home/neil/PhpstormProjects/sftp-user-create/vendor/php-amqplib/php-amqplib/PhpAmqpLib/Wire/IO/StreamIO.php on line 214