Score:0

How do I make RabbitMQ listen to other IP Addresses besides Local Host/127.0.0.1?

mo flag

I am trying to remotely send a message to RabbitMQ server. I do not have RabbitMQ installed on my machine but the device I am trying to send the message to does have RabbitMQ installed. Whenever I try sending a message I always receive a connection time out error. I think I am having this issue because RabbitMQ is only listening to local host. My files and error is listed below. Any help would be appreciated.

Here is my error when I run send.php:

PHP Fatal error:  Uncaught PhpAmqpLib\Exception\AMQPIOException: stream_socket_client(): Unable to connect to tcp://ipaddress:5672 (Connection timed out) in /home///vendor/php-amqplib/php-amqplib/PhpAmqpLib/Wire/IO/StreamIO.php:108
Stack trace:
#0 /home////vendor/php-amqplib/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php(255): PhpAmqpLib\Wire\IO\StreamIO->connect()
#1 /home//vendor/php-amqplib/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php(237): PhpAmqpLib\Connection\AbstractConnection->connect()
#2 /home///vendor/php-amqplib/php-amqplib/PhpAmqpLib/Connection/AMQPStreamConnection.php(64): PhpAmqpLib\Connection\AbstractConnection->__construct()
#3 /home///send.php(7): PhpAmqpLib\Connection\AMQPStreamConnection->__construct()
#4 {main}
  thrown in /home///vendor/php-amqplib/php-amqplib/PhpAmqpLib/Wire/IO/StreamIO.php on line 108
user@user-Parallels-ARM-Virtual-Machine:~-$ php send.php
PHP Fatal error:  Uncaught PhpAmqpLib\Exception\AMQPTimeoutException: The connection timed out after 3 sec while awaiting incoming data in /home///vendor/php-amqplib/php-amqplib/PhpAmqpLib/Wire/AMQPIOReader.php:102
Stack trace:
#0 /home///vendor/php-amqplib/php-amqplib/PhpAmqpLib/Wire/AMQPIOReader.php(60): PhpAmqpLib\Wire\AMQPIOReader->wait()
#1 /home//I/vendor/php-amqplib/php-amqplib/PhpAmqpLib/Wire/AMQPReader.php(35): PhpAmqpLib\Wire\AMQPIOReader->rawread()
#2 /home/l//vendor/php-amqplib/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php(601): PhpAmqpLib\Wire\AMQPReader->read()
#3 /home///vendor/php-amqplib/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php(658): PhpAmqpLib\Connection\AbstractConnection->wait_frame()
#4 /home///vendor/php-amqplib/php-amqplib/PhpAmqpLib/Channel/AbstractChannel.php(235): PhpAmqpLib\Connection\AbstractConnection->wait_channel()
#5 /home///vendor/php-amqplib/php-amqplib/PhpAmqpLib/Channel/AbstractChannel.php(352): PhpAmqpLib\Channel\AbstractChannel->next_frame()
#6 /home//I/vendor/php-amqplib/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php(266): PhpAmqpLib\Channel\AbstractChannel->wait()
#7 /home///vendor/php-amqplib/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php(237): PhpAmqpLib\Connection\AbstractConnection->connect()
#8 /home///vendor/php-amqplib/php-amqplib/PhpAmqpLib/Connection/AMQPStreamConnection.php(64): PhpAmqpLib\Connection\AbstractConnection->__construct()
#9 /home///send.php(7): PhpAmqpLib\Connection\AMQPStreamConnection->__construct()
#10 {main}
  thrown in /home///vendor/php-amqplib/php-amqplib/PhpAmqpLib/Wire/AMQPIOReader.php on line 102

Here is my Send.php file where I send a message to the other device/RabbitMQ:

<?php

require_once __DIR__ . '/vendor/autoload.php';
use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;

$connection = new AMQPStreamConnection('ipaddress', 15672, 'user', 'pass');
$channel = $connection->channel();

$channel->queue_declare('hello', false, false, false, false);

$msg = new AMQPMessage('Hello World!');
$channel->basic_publish($msg, '', 'hello');

echo " [x] Sent 'Hello World!'\n";

$channel->close();
$connection->close();
?>

Here is my Receive.php file which the other device/RabbitMQ runs:

<?php

require_once __DIR__ . '/vendor/autoload.php';
use PhpAmqpLib\Connection\AMQPStreamConnection;

$connection = new AMQPStreamConnection('10.242.125.55', 15672, 'guest', 'guest');
$channel = $connection->channel();

$channel->queue_declare('hello', false, false, false, false);

echo " [*] Waiting for messages. To exit press CTRL+C\n";

$callback = function ($msg) {
    echo ' [x] Received ', $msg->body, "\n";
};

$channel->basic_consume('hello', '', false, true, false, false, $callback);

while ($channel->is_open()) {
    $channel->wait();
}

$channel->close();
$connection->close();
?>
user535733 avatar
cn flag
This seems covered in the RabbitMQ documentation. Localhost access only is the default (security). You change it in the RabbitMQ config file on the remote machine.
Gemma B avatar
mo flag
@user535733 every time the person with RabbitMQ restarts RabbitMQ after editing the RabbitMQ-env.conf and RabbitMQ.conf files they can never restart RabbitMQ. This might be because they created both of the configuration files because they did not have them. Do you have any idea why we are receiving this error?
user535733 avatar
cn flag
Already stated why I think you are receiving the error in the comment above. What OS and version is the RabbitMQ server running upon? "*they can never restart RabbitMQ*" seems both puzzling and suspicious.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.