dongshen7561 2019-03-05 07:59
浏览 419

面对通过rabbitmq(amqp协议)从云向设备iot集线器发送消息的问题

I want to send message from cloud to device iot hub with amqp protocol for this i am using rabbitmq message broker with the reference in php. I have tried the below code on 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!'
";    
    $channel->close();
    $connection->close();

when i run this send.php file i am getting error:

fatal error: Uncaught PhpAmqpLib\Exception\AMQPConnectionClosedException: Broken pipe or closed connection in C:\xampp\htdocs\amqp\vendor\php-amqplib\php-amqplib\PhpAmqpLib\Wire\IO\StreamIO.php:222

Please help me out.

  • 写回答

1条回答 默认 最新

  • dongyong1897 2019-03-06 14:50
    关注

    You can't send Cloud-to-Device messages from your IotHub using rabbitmq.

    " You send cloud-to-device messages through a service-facing endpoint (/messages/devicebound). A device then receives the messages through a device-specific endpoint (/devices/{deviceId}/messages/devicebound).

    To target each cloud-to-device message at a single device, IoT Hub sets the to property to /devices/{deviceId}/messages/devicebound. "

    Read more here.

    You can\should leverage the Azure IoT Hub Service SDKs - see here.

    评论

报告相同问题?

悬赏问题

  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法