[英]how to send message from rabbitMQ to iot hub device?
I am trying to send message from rabbitMQ to IoT hub device named as dvc-test
with php, i referred official documentation and tried the send.php
code like below: 我正在尝试使用php从RabbitMQ向名为dvc
dvc-test
IoT中心设备发送消息,我参考了官方文档并尝试了send.php
代码,如下所示:
<?php
require_once __DIR__ . '/vendor/autoload.php';
use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;
$host = '[MYHUBNAME].azure-devices.net';
$userName = 'XXXXXXXX'; //confused which iot hub crediential should comes device or iothub
$password = 'XXXXXXXX'; //confused which iot hub crediential should comes device or iothub
$connection = new AMQPStreamConnection($host, 5672, $userName, $password);
$channel = $connection->channel();
$channel->queue_declare('hello', false, false, false, false);
$json = '{"id":1, "value":"test"}';
$msg = new AMQPMessage($json);
$channel->basic_publish($msg, '', 'hello');
echo " [x] Sent ";
$channel->close();
$connection->close();
It worked for localhost with default given parameteres given in documentation, But if i tried with iot hub credientials it does not work for me. 它适用于本地主机,具有文档中给出的默认给定参数,但是,如果我尝试使用iot hub凭证,则对我不起作用。
please help 请帮忙
Please check rabbitmq logs if you see any connections from your ip. 如果您看到来自IP的任何连接,请检查Rabbitmq日志。 If there is nothing in log, then maybe some firewall is blocking amqp connection.
如果日志中没有任何内容,则可能是某些防火墙阻止了amqp连接。
BTW, I assume that you are sending messages TO rabbimq, not from. 顺便说一句,我假设您是向rabbimq发送消息,而不是从。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.