2017-09-22 26 views
0

私は最新のバージョンog php-amqpをインストールしましたが、私は方法channel()を使用しているようです。これは、コード未定義のメソッドを呼び出す

<?php 
ini_set('display_errors', 1); 
ini_set('display_startup_errors', 1); 
error_reporting(E_ALL); 


require_once __DIR__.'/vendor/autoload.php'; 

use PhpAmqpLib\Connection\AMQPStreamConnection; 
use PhpAmqpLib\Message\AMQPMessage; 


$cnn = new AMQPConnection(); 

// set the login details 
$cnn->setLogin('guest'); 
$cnn->setPassword('guest'); 

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

$channel = $cnn->channel(); 

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

$data = 'lorem ipsum'; 

$msg = new AMQPMessage($data, array('delivery_mode' => 2)); 
$channel->basic_publish($msg, '', 'email_queue'); 

?> 

であり、これは私が、私はそれをこのように解決し

Established a connection to the broker Fatal error: Uncaught Error: Call to undefined method AMQPConnection::channel() in /var/www/html/rabbit.php:26 Stack trace: #0 {main} thrown in /var/www/html/rabbit.php on line 26

答えて

0

得るものです

<?php 
ini_set('display_errors', 1); 
ini_set('display_startup_errors', 1); 
error_reporting(E_ALL); 


require_once __DIR__.'/vendor/autoload.php'; 

use PhpAmqpLib\Connection\AMQPStreamConnection; 
use PhpAmqpLib\Message\AMQPMessage; 


$connection = new AMQPStreamConnection('localhost', 5672, 'guest', 'guest'); 
$cnn = new AMQPConnection(); 

$channel = $connection->channel(); 


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


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

$data = rand(35,887); 

$msg = new AMQPMessage($data, array('delivery_mode' => 2)); 
$channel->basic_publish($msg, '', 'rand'); 

$channel->close(); 
$connection->close(); 
?> 
関連する問題