本文整理汇总了PHP中AMQPQueue::declare方法的典型用法代码示例。如果您正苦于以下问题:PHP AMQPQueue::declare方法的具体用法?PHP AMQPQueue::declare怎么用?PHP AMQPQueue::declare使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AMQPQueue
的用法示例。
在下文中一共展示了AMQPQueue::declare方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Run
public function Run()
{
// Declare a new exchange
$ex = new AMQPExchange($this->cnn);
$ex->declare('game', AMQP_EX_TYPE_FANOUT);
// Create a new queue
$q1 = new AMQPQueue($this->cnn);
$q1->declare('queue1');
$q2 = new AMQPQueue($this->cnn);
$q2->declare('queue2');
// Bind it on the exchange to routing.key
//$ex->bind('queue1', 'broadcast=true,target=queue1,x-match=any');
$ex->bind('queue1', '');
$ex->bind('queue2', '');
$msgBody = 'hello';
// Publish a message to the exchange with a routing key
$ex->publish($msgBody, 'foo');
// Read from the queue
$msg = $q1->consume();
$this->AssertEquals(count($msg), 1);
$this->AssertEquals($msg[0]['message_body'], $msgBody, 'message not equal');
// Read from the queue
$msg = $q2->consume();
$this->AssertEquals(count($msg), 1);
$this->AssertEquals($msg[0]['message_body'], $msgBody, 'message not equal');
$this->AddMessage(var_export($msg[0], true));
}
示例2: get
public function get($queueName, $timeout = null)
{
if (null === $this->queue) {
$queue = new \AMQPQueue($this->channel);
$queue->setName($queueName);
$queue->declare();
}
return unserialize($queue->consume());
}
示例3: setupUserQueue
public function setupUserQueue($userid)
{
$q = new \AMQPQueue($this->cnn);
$q->declare($userid);
$key = $this->buildRouteKeyForPrivate($userid);
$this->channel->bind($userid, \Constant\AMQPCommand::BingoBroadcast);
$this->channel->bind($userid, \Constant\AMQPCommand::BingoPrivatePrefix . $userid . '.#');
return $q;
}
示例4: init
/**
* AMQP queue initialization
* @param string $name Queue name
* @param string $mode Access mode: r is for reading and w is for writing
* @return \AMQPQueue
*/
public function init($name, $mode = 'w')
{
$queue = new \AMQPQueue($this->channel);
$queue->setName($name);
$queue->declare();
if ($mode == 'r') {
$queue->bind('Celium', $name);
}
return $queue;
}
示例5: Run
public function Run()
{
// Declare a new exchange
$ex = new AMQPExchange($this->cnn);
$ex->declare('game', AMQP_EX_TYPE_TOPIC);
// Create a new queue
$q1 = new AMQPQueue($this->cnn);
$q1->declare('queue1');
$q1->purge('queue1');
$q2 = new AMQPQueue($this->cnn);
$q2->declare('queue2');
$q1->purge('queue2');
$q3 = new AMQPQueue($this->cnn);
$q3->declare('queue3');
$q3->purge('queue3');
$options = array('min' => 0, 'max' => 10, 'ack' => true);
// Bind it on the exchange to routing.key
$ex->bind('queue1', 'game1.#');
$ex->bind('queue2', 'game1.#');
$ex->bind('queue3', 'game1.#');
$ex->bind('queue3', 'queue3.#');
$msgbody1 = 'hello';
// Publish a message to the exchange with a routing key
$result = $ex->publish($msgbody1, 'game1.msg');
$this->AssertEquals($result, TRUE, 'publish message failed');
$msgbody2 = 'world';
// Publish a message to the exchange with a routing key
$result = $ex->publish($msgbody2, 'game1.msg');
$this->AssertEquals($result, TRUE, 'publish message failed');
$msgbody3 = 'hello player3';
// Publish a message to the exchange with a routing key
$result = $ex->publish($msgbody3, 'queue3.command');
$this->AssertEquals($result, TRUE, 'publish message failed');
// Read from the queue
$msg = $q1->consume($options);
$this->AddMessage(var_export($msg, true));
$this->AssertEquals(count($msg), 2);
$this->AssertEquals($msg[0]['message_body'], $msgbody1, 'message not equal');
$this->AssertEquals($msg[1]['message_body'], $msgbody2, 'message not equal');
// Read from the queue
$msg = $q2->consume($options);
$this->AssertEquals(count($msg), 2);
$this->AssertEquals($msg[0]['message_body'], $msgbody1, 'message not equal');
$this->AssertEquals($msg[1]['message_body'], $msgbody2, 'message not equal');
// Read from the queue
$msg = $q3->consume($options);
$this->AddMessage(var_export($msg, true));
$this->AssertEquals(count($msg), 3);
$this->AssertEquals($msg[0]['message_body'], $msgbody1, 'message not equal');
$this->AssertEquals($msg[1]['message_body'], $msgbody2, 'message not equal');
$this->AssertEquals($msg[2]['message_body'], $msgbody3, 'message not equal');
$msg = $q3->consume($options);
$this->AssertEquals(count($msg), 0);
}
示例6: Run
public function Run()
{
// Declare a new exchange
$ex = new AMQPExchange($this->cnn);
$ex->declare('game', AMQP_EX_TYPE_HEADER);
// Create a new queue
$q1 = new AMQPQueue($this->cnn);
$q1->declare('queue1');
$q1->purge('queue1');
$q2 = new AMQPQueue($this->cnn);
$q2->declare('queue2');
$q1->purge('queue2');
$q3 = new AMQPQueue($this->cnn);
$q3->declare('queue3');
$q3->purge('queue3');
$options = array('min' => 0, 'max' => 10, 'ack' => true);
// Bind it on the exchange to routing.key
$ex->bind('queue1', 'broadcast=1,target=1,x-match=any');
$ex->bind('queue2', 'broadcast=1,target=2,x-match=any');
$ex->bind('queue3', 'broadcast=1,target=3,x-match=any');
$msgbody1 = 'hello';
// Publish a message to the exchange with a routing key
$result = $ex->publish($msgbody1, NULL, AMQP_IMMEDIATE, array('headers' => array('broadcast' => 1)));
$this->AssertEquals($result, TRUE, 'publish message failed');
$msgbody2 = 'world';
// Publish a message to the exchange with a routing key
$result = $ex->publish($msgbody2, NULL, AMQP_IMMEDIATE, array('headers' => array('broadcast' => 1)));
$this->AssertEquals($result, TRUE, 'publish message failed');
$msgbody3 = 'queue3';
// Publish a message to the exchange with a routing key
$result = $ex->publish($msgbody1, NULL, AMQP_IMMEDIATE, array('headers' => array('target' => 3)));
$this->AssertEquals($result, TRUE, 'publish message failed');
// Read from the queue
$msg = $q1->consume($options);
$this->AddMessage(var_export($msg, true));
$this->AssertEquals(count($msg), 2);
//$this->AssertEquals($msg[0]['message_body'], $msgbody1, 'message not equal');
//$this->AssertEquals($msg[1]['message_body'], $msgbody2, 'message not equal');
// Read from the queue
$msg = $q2->consume($options);
$this->AssertEquals(count($msg), 2);
//$this->AssertEquals($msg[0]['message_body'], $msgbody1, 'message not equal');
//$this->AssertEquals($msg[1]['message_body'], $msgbody2, 'message not equal');
// Read from the queue
$msg = $q3->consume($options);
$this->AssertEquals(count($msg), 3);
//$this->AssertEquals($msg[0]['message_body'], $msgbody1, 'message not equal');
//$this->AssertEquals($msg[1]['message_body'], $msgbody2, 'message not equal');
//$this->AssertEquals($msg[2]['message_body'], $msgbody3, 'message not equal');
}
示例7: Run
public function Run()
{
// Create a new queue
$q1 = new AMQPQueue($this->cnn);
$q1->declare('queue1');
$q1->purge('queue1');
$options = array('min' => 0, 'max' => 10, 'ack' => true);
// Bind it on the exchange to routing.key
$q1->bind(\Constant\AMQPChannelConstant::AMF, \Constant\AMQPCommand::BingoBroadcast);
// Read from the queue
while (TRUE) {
$msg = $q1->consume($options);
var_dump($msg);
}
}
示例8: AMQPConnection
include 'image_analyzer.php';
include 'storage.php';
/**
* Подключаемся к брокеру и точке обмена сообщениями
*/
$rabbit = new AMQPConnection(array('host' => '127.0.0.1', 'port' => '5672', 'login' => 'guest', 'password' => 'guest'));
$rabbit->connect();
$channel = new AMQPChannel($rabbit);
$queue = new AMQPExchange($channel);
$queue->setName('amq.direct');
/**
* Добавляем очередь откуда будем брать страницы
*/
$q = new AMQPQueue($channel);
$q->setName('images_to_scan');
$q->declare();
$q->bind('amq.direct', 'analyze_image');
/**
* Обрабатываем пока в очереди не закончатся сообщения
*/
while (true) {
$image = $q->get();
if ($image) {
$url = $image->getBody();
echo "Checking: {$url}\n";
$analyzer = new ImageAnalyzer($url);
/**
* Если картинка еще не была проанализирована, обрабатываем и добавляем в индекс
*/
$analyzer->analyze();
$q->ack($image->getDeliveryTag());
示例9: readAll
/**
* Read all messages
*
* @access public
*
* @param string $chat name chat room
* @param string $route name route
* @param string $nameReader name queue
*
* @return array
* @throws \AMQPConnectionException
* @throws \AMQPQueueException
* @throws \AMQPChannelException
*/
public function readAll($chat, $route, $nameReader)
{
$queue = new \AMQPQueue($this->channel);
$queue->setName($nameReader);
/** @noinspection PhpUndefinedMethodInspection */
$queue->declare();
$queue->bind($chat, $route);
$result = [];
while ($envelop = $queue->get()) {
$queue->ack($envelop->getDeliveryTag());
$result[] = $envelop;
}
return $result;
}
示例10: AMQPConnection
<?php
require 'config.php';
$connection = new AMQPConnection($connect);
$connection->connect();
$channel = new AMQPChannel($connection);
$exchange = new AMQPExchange($channel);
$exchange->setName($exname);
$exchange->setType(AMQP_EX_TYPE_TOPIC);
$exchange->setFlags(AMQP_DURABLE);
$exchange->declare();
$queue = new AMQPQueue($channel);
$queue->setName($qname);
$queue->setFlags(AMQP_DURABLE);
$queue->declare();
$queue->bind($exname, $routekey);
$channel->startTransaction();
$message = json_encode(array('Hello World! 测试消息!', 'TOPIC'));
$exchange->publish($message, $routekey);
$channel->commitTransaction();
$connection->disconnect();
示例11: AMQPQueue
<?php
use Utility\AMQPConnect;
error_reporting(E_ALL | E_STRICT);
require_once 'bingo/odmconfig.php';
require_once __DIR__ . '/BingoStreamAMQPQueue.php';
use Constant\ErrorCode, Doctrine\Common\ClassLoader, Doctrine\Common\Annotations\AnnotationReader, Doctrine\Common\Annotations\IndexedReader, Doctrine\ODM\MongoDB\DocumentManager, Doctrine\MongoDB\Connection, Doctrine\ODM\MongoDB\Configuration, Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver;
// Initialize
set_time_limit(0);
// Create a new queue
$amqpcon = AMQPConnect::getInstance();
$cnn = $amqpcon->getConnection();
$q1 = new AMQPQueue($cnn);
$q1->declare('queue1');
$options = array('min' => 1, 'max' => 20);
// Bind it on the exchange to routing.key
//$q1->bind(\Constant\AMQPChannelConstant::AMF, \Constant\AMQPCommand::BingoBroadcast);
//$q1->bind(\Constant\AMQPChannelConstant::AMF, '4ebe6492aeac033931000000');
//$q1->bind(\Constant\AMQPChannelConstant::AMF, '#');
$q1->bind('4ebe6492aeac033931000000', 'bingo.#');
$logger = new \Utility\KLogger('/var/log/bingo/teststream.log', \Utility\GlobalConfiguration::GetInstance()->Config[\Constant\SectionType::Logging][\Constant\ConfigKey::LoggingLevel]);
do {
// Read from the queue
$messages = $q1->consume($options);
if ($messages != NULL) {
foreach ($messages as $msg) {
echo $msg['message_body'];
$logger->LogDebug($msg['message_body'] . PHP_EOL);
}
}
} while (1);
示例12: AMQPChannel
//创建channel
$channel = new AMQPChannel($conn);
//注:队列跟exchange 都需要基于channel channel基于connection
$ex = new AMQPExchange($channel);
//新建exchange
$ex->setName($e_name);
//创建exchange的名字
$ex->setType(AMQP_EX_TYPE_DIRECT);
//TPYE DIRECT 添加进绑定key的所有的队列,FANOUT 添加进绑定的所有队列 TOPIC 自定义的规则 . 连接多个队列 #为通配符
$ex->setFlags(AMQP_DURABLE | AMQP_AUTODELETE);
echo "exchange status:" . $ex->declare();
echo "\n";
//创建队列
$q = new AMQPQueue($channel);
//新建队列
//设置队列的名字 如果不存在则自动添加
$q->setName($q_name);
$q->setFlags(AMQP_DURABLE | AMQP_AUTODELETE);
//添加属性 DURABLE持久的 AUTODELEETE没有连接自动删除
echo "queue status:" . $q->declare();
//声明队列
echo "\n";
echo 'queue bind:' . $q->bind($e_name, $r_key);
//将队列绑定到routingKey
echo "\n";
$channel->startTransaction();
echo "send: " . $ex->publish($message, $r_key);
//将数据通过routingKey发送
$channel->commitTransaction();
$conn->disconnect();
//关闭连接
示例13: getAMQPExchange
protected function getAMQPExchange()
{
if (is_null(self::$_AMQPExchange)) {
$channel = new AMQPChannel($this->getAMQPConnection());
$exchange = new AMQPExchange($channel);
$exchange->setName($this->getExchangeName());
$exchange->setType($this->getExchangeType());
$exchange->setFlags(AMQP_DURABLE);
$exchange->declare();
$queue = new AMQPQueue($channel);
$queue->setName($this->getQueueName());
$queue->setFlags(AMQP_DURABLE);
$queue->setArgument('x-ha-policy', 'all');
$queue->declare();
$queue->bind($this->getExchangeName(), $this->getRoutingKey());
self::$_AMQPExchange = $exchange;
}
return self::$_AMQPExchange;
}
示例14: getTotalNum
public function getTotalNum()
{
$params = array('host' => 'localhost', 'port' => 5672, 'login' => 'guest', 'password' => 'guest', 'vhost' => '/kwd');
$conn = new AMQPConnection($params);
$conn->connect();
$channel = new AMQPChannel($conn);
$queue = new AMQPQueue($channel);
$queue->setName('q_proxy');
$queue->setFlags(AMQP_PASSIVE);
$messageCount = $queue->declare();
return $messageCount;
}
示例15: array
<?php
echo "<pre>";
$conn_args = array('host' => 'localhost', 'port' => 5672, 'login' => 'guest', 'password' => 'guest', 'vhost' => '/');
$q_name = 't1';
//获取队列名称
$conn = new AMQPConnection($conn_args);
$conn->connect();
$channel = new AMQPChannel($conn);
$q = new AMQPQueue($channel);
$q->setName($q_name);
$q->setFlags(AMQP_DURABLE | AMQP_AUTODELETE);
while ($a = $q->declare()) {
echo "queue status:" . $a;
echo "=============\n";
$message = $q->get(AMQP_AUTOACK);
print_r($message->getBody());
echo "\n";
}
$conn->disconnect();