简体   繁体   中英

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
    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.

please help

Please check rabbitmq logs if you see any connections from your ip. If there is nothing in log, then maybe some firewall is blocking amqp connection.

BTW, I assume that you are sending messages TO rabbimq, not from.

You can find an example here how to send messages with low level AMQP. For the authentication you need to generate a SAS token based on your device key.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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