简体   繁体   English

如何从rabbitMQ向物联网集线器设备发送消息?

[英]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发送消息,而不是从。

You can find an example here how to send messages with low level AMQP. 您可以在此处找到一个示例说明如何使用低级别的AMQP发送消息。 For the authentication you need to generate a SAS token based on your device key. 对于身份验证,您需要根据设备密钥生成SAS令牌。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM