我想用amqp协议从云端向设备iot hub发送消息,我正在使用带有reference的rabbitmq消息代理。我在localhost上尝试了以下代码:
//send.php
<?php
require_once __DIR__ . '/vendor/autoload.php';
use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;
$connection = new AMQPStreamConnection('HUBNAME.azure-devices.net', 5671
, 'HUBNAME.azure-devices.net/DEVICENAME/?api-version=2018-06-30'
, 'SharedAccessSignature sr=HUBNAME.azure-devices.net
&sig=XXXX&se=XXXX&skn=iothubowner');
$channel = $connection->channel();
$channel->queue_declare('hello', false, false, false, false);
$json = '{"id":123, "value":"xyz"}';
$msg = new AMQPMessage($json);
$channel->basic_publish($msg, '', 'hello');
echo " [x] Sent 'Hello World!'\n";
$channel->close();
$connection->close();
当我运行这个send.php
文件时,我收到错误:
致命错误:未捕获PhpAmqpLib \ Exception \ AMQPConnectionClosedException:C:\ xampp \ htdocs \ amqp \ vendor \ php-amqplib \ php-amqplib \ PhpAmqpLib \ Wire \ IO \ StreamIO.php中管道断开或已关闭连接:222
请帮帮我。