sintonia/analyzer/tools/message_sender.php

47 lines
1.1 KiB
PHP
Raw Permalink Normal View History

<?
require_once('php-amqplib/amqp.inc');
//use PhpAmqpLibConnectionAMQPConnection;
//use PhpAmqpLibMessageAMQPMessage;
define('HOST', '127.0.0.1');
define('PORT', '5672');
define('USER', 'airtime');
define('PASS', 'QEFKX5GMKT4YNMOAL9R8');
define('VHOST', '/airtime');//'/airtime');
$exchange = "airtime-uploads";
$exchangeType = "topic";
$queue = "airtime-uploads";
$routingKey = ""; //"airtime.analyzer.tasks";
if ($argc <= 1)
{
echo("Usage: " . $argv[0] . " message\n");
exit();
}
2021-05-27 16:33:20 +02:00
$message = $argv[1];
$connection = new AMQPStreamConnection(HOST, PORT, USER, PASS, VHOST);
if (!isset($connection)) {
echo "Failed to connect to the RabbitMQ server.";
return;
}
$channel = $connection->channel();
2021-05-27 16:33:20 +02:00
// declare/create the queue
$channel->queue_declare($queue, false, true, false, false);
2021-05-27 16:33:20 +02:00
// declare/create the exchange as a topic exchange.
$channel->exchange_declare($exchange, $exchangeType, false, true, false);
$msg = new AMQPMessage($message, array("content_type" => "text/plain"));
$channel->basic_publish($msg, $exchange, $routingKey);
print "Sent $message ($routingKey)\n";
$channel->close();
$connection->close();