how to upload a file from php to amqp

Posted by user2462648 on Stack Overflow See other posts from Stack Overflow or by user2462648
Published on 2013-07-01T10:15:35Z Indexed on 2013/07/01 17:07 UTC
Read the original article Hit count: 283

Filed under:
|
|

i want to know... how can i send a file to a rabbitmq queue from php. i have gone through many examples most of them didnt work. below is a consumer producer example which is near to working. Below is a the 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();
    ?>

consumer.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);
?>

according to the example provided in the rabbitmq manual, i need to run consumer(php consumer.php) first in one terminal and the publisher (php publisher.php 1 2 file/path.png) in another terminal, i will get a "Adding points to user: 2" message in the consumer terminal. iam not getting this message at all. can you suggest where iam going wrong

© Stack Overflow or respective owner

Related posts about php

Related posts about rabbitmq