2012-06-22 2 views
0

pika 라이브러리를 사용하여 rabbitMQ 대기열에 메시지를 푸시하는 python 애플리케이션이 있습니다.RabbitMQ - PHP/Python 소비자 문제

message='hola' 
credentials = pika.PlainCredentials('guest', 'guest') 
connection = pika.BlockingConnection(pika.ConnectionParameters(credentials=credentials, host='localhost')) 
channel = connection.channel() 
channel.queue_declare(queue='myqueue') 
channel.basic_publish(exchange='',routing_key='myqueue',body=message) 
connection.close() 

그게 효과가 있습니다.

PHP 응용 프로그램에서 이러한 메시지를 사용해야합니다. 나는이 페이지에서 AQMP 예에서 언급 한 바와 같이이 시도 -

Fatal error: Uncaught exception 'Exception' with message 'Error parsing parameters.' in /home/webroot/amqptest.php:12 Stack trace: #0 /home/webroot/amqptest.php(12): AMQPQueue->declare('myqueue') #1 {main} thrown in /home/webroot/amqptest.php on line 12 
+0

amqp_queue.c이 때 오류가 발생 않았다

AMQPQueue::__construct(AMQPChannel channel) 

AMQP 패키지의 소스 코드 : 당신은 큐의 생성자의 정의를 찾을 수 있습니까? 당신이 연결할 때입니까? 아니면 당신이 소비하고있는 부분에서? –

답변

1

이 작동합니다 - - http://www.php.net/manual/en/class.amqpqueue.php (체크 기능 리시버)

$cnn = new AMQPConnection((array("host"=>"ec2-xxx-xx-xx-xxx.ap-southeast-1.compute.amazonaws.com","login"=>"guest", "password"=>"guest"))); 
if ($cnn->connect()) { 
    echo "Established a connection to the broker"; 
} 
else { 
    echo "Cannot connect to the broker"; 
} 

    $queue = new AMQPQueue($cnn); 
    $queue->declare('myqueue'); 
    $queue->bind('', 'myqueue'); 

$msg=$queue->get(AMQP_AUTOACK); 
echo $msg->getBody(); 

이 예외를 throw하지만 마음에 곰 오류 처리가 없습니다 또는 반복하는 모든 루프는 메시지를 선택합니다. 그것은 나를 위해 브로커로부터 개별 메시지를 성공적으로 dequeue/receive하지만, 빈 queue를 다시 실행하면 충돌합니다.

<?php 

$cnn = new AMQPConnection(); 
$cnn->setLogin("guest"); 
$cnn->setPassword("guest"); 
$cnn->setHost("localhost"); 

if ($cnn->connect()) { 
    echo "Established a connection to the broker\n"; 
} 
else { 
    echo "Cannot connect to the broker\n"; 
} 

$channel = new AMQPChannel($cnn); 
$queue = new AMQPQueue($channel); 
$queue->setName('myqueue'); 

// the default/nameless) exchange does not require a binding 
// as the broker declares a binding for each queue with key 
// identical to the queue name. error 403 if you try yourself. 
//$queue->bind('', 'myqueue'); 

$msg=$queue->get(AMQP_AUTOACK); 

echo $msg->getBody(); 
echo "\n"; 

?> 

특히 AMQPConnection은 배열이 아닌 속성을 통해 구성해야합니다. AMQPChannel을 사용하여 AMQPQueue 객체에 전달해야합니다. 기본 교환의 대기열에 대한 바인딩은 작동하지 않거나 필요하지 않습니다. 효과가

:-) $ queue-> 바인딩을 보여 줄의 주석을 시도 보려면 내가 공공 요점으로 Github에서 위로 두 스크립트의 사본을 넣어 - 나는 문서가 잘못 생각 https://gist.github.com/2988379

0

. AMQPConnection이 아닌 큐를 작성하려면 AMQPChannel이 필요합니다.

관련 문제