我想知道...如何从 php 将文件发送到 rabbitmq 队列。我经历了很多例子,其中大多数都没有用。下面是一个即将工作的消费者生产者示例。下面是一个publisher.php
<?php
require_once('../php-amqplib/amqp.inc');
include('../config.php');
$conn = new AMQPConnection(HOST, PORT, USER, PASS, VHOST);
$channel = $conn->channel();
$channel->exchange_declare('upload-pictures','direct', false, true, false);
$metadata = json_encode(array(
'image_id' => $argv[1],
'user_id' => $argv[2],
'image_path' => $argv[3]
));
$msg = new AMQPMessage($metadata, array('content_type' => 'text/plain','delivery_mode' => 2));
$channel->basic_publish($msg, 'upload-pictures');
$channel->close();
$conn->close();
?>
消费者.php
<?php
require_once('../php-amqplib/amqp.inc');
include('../config.php');
$conn = new AMQPConnection(HOST, PORT, USER, PASS,VHOST);
$channel = $conn->channel();
$queue = 'add-points';
$consumer_tag = 'consumer';
$channel->exchange_declare('upload-pictures','direct', false, true, false);
$channel->queue_declare('add-points',false, true, false, false);
$channel->queue_bind('add-points', 'upload-pictures');
$consumer = function($msg){};
$channel->basic_consume($queue,$consumer_tag,false,false,false,false,$consumer);
?>
根据rabbitmq手册中提供的示例,我需要先在一个终端中运行消费者(php consumer.php),然后在另一个终端中运行发布者(php publisher.php 1 2 file/path.png),我会得到一个“向用户添加积分:消费者终端中的 2" 消息。我根本没有收到此消息。你能建议我哪里出错了吗