当前位置: 首页>>代码示例>>PHP>>正文


PHP AMQPExchange::declare方法代码示例

本文整理汇总了PHP中AMQPExchange::declare方法的典型用法代码示例。如果您正苦于以下问题:PHP AMQPExchange::declare方法的具体用法?PHP AMQPExchange::declare怎么用?PHP AMQPExchange::declare使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AMQPExchange的用法示例。


在下文中一共展示了AMQPExchange::declare方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1:

 function __construct()
 {
     $connection = new \AMQPConnection();
     $connection->connect();
     if (!$connection->isConnected()) {
         throw new \AMQPConnectionException('Rabbit is not connected');
     }
     $this->channel = new \AMQPChannel($connection);
     $this->exchange = new \AMQPExchange($this->channel);
     //$this->exchange->delete('Celium');
     $this->exchange->setName('Celium');
     $this->exchange->setType('direct');
     //$this->exchange->setFlags(\AMQP_DURABLE);
     $this->exchange->declare();
 }
开发者ID:zarincheg,项目名称:celium,代码行数:15,代码来源:Rabbit.php

示例2: 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));
 }
开发者ID:JasonOcean,项目名称:iOS_Interest_Group,代码行数:27,代码来源:amqp_ut.php

示例3: 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);
 }
开发者ID:JasonOcean,项目名称:iOS_Interest_Group,代码行数:54,代码来源:amqp_topic_ut.php

示例4: 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');
 }
开发者ID:JasonOcean,项目名称:iOS_Interest_Group,代码行数:50,代码来源:amqp_xmatch_ut.php

示例5: __construct

 public function __construct($AMQPConfiguration, $exchangeName = '')
 {
     if (!class_exists('AMQPConnection')) {
         throw new \LogicException("Can't find AMQP lib");
     }
     $ampq = new \AMQPConnection($AMQPConfiguration);
     if ($ampq->connect()) {
         $channel = new \AMQPChannel($ampq);
         $exchange = new \AMQPExchange($channel);
         $exchange->setName($exchangeName);
         $exchange->declare();
         $this->channel = $channel;
         $this->exchange = $exchange;
     } else {
         throw new \RuntimeException("Can't connect to AMQP server");
     }
 }
开发者ID:rcambien,项目名称:riverline-worker-bundle,代码行数:17,代码来源:AMQP.php

示例6: writeRMQ

/**
 * 批量打入v3work_seo_pdrec数据,用于预热本企业推荐产品
 */
function writeRMQ($exchangeName = 'v3www', $router, $data = '')
{
    $cfg = array('host' => '192.168.8.18', 'port' => '5672', 'login' => 'v3work', 'password' => 'gc7232275', 'vhost' => '/');
    if (empty($exchangeName) || empty($data) || empty($cfg)) {
        return false;
    }
    $reTryNum = 3;
    $errMsg = array();
    do {
        try {
            //建立到rmq服务器链接
            $connection = new AMQPConnection($cfg);
            $connection->connect();
            //建立channel对象
            $channel = new AMQPChannel($connection);
            //建立交换机
            $exchange = new AMQPExchange($channel);
            $exchange->setName($exchangeName);
            $exchange->setType(AMQP_EX_TYPE_DIRECT);
            $exchange->setFlags(AMQP_DURABLE);
            $exchange->declare();
            $routingKey = $router;
            //发消息
            $ret = $exchange->publish($data, $routingKey, AMQP_NOPARAM, array('delivery_mode' => '2'));
            //关闭链接
            $connection->disconnect();
            return $ret;
        } catch (Exception $e) {
            $connection->disconnect();
            $errMsg[] = $e->getMessage();
            usleep(5000);
            $reTryNum -= 1;
        }
    } while ($reTryNum);
    return false;
}
开发者ID:tianyunchong,项目名称:php,代码行数:39,代码来源:simrec.php

示例7: 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();
开发者ID:wanggeopens,项目名称:own-libs,代码行数:21,代码来源:producer.php

示例8: AMQPChannel

$q_name = 'q_test5';
//队列名称
$r_key = 'key_test1';
//消息
$message = json_encode(array("HelloWorld"));
//创建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();
开发者ID:flydement,项目名称:MyTest,代码行数:31,代码来源:producter.php

示例9: 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;
 }
开发者ID:rurri,项目名称:log4php-graylog2,代码行数:19,代码来源:LoggerAppenderAMQP.php

示例10: die

printf("--------- %d  ---------\n", __LINE__);
var_dump($res);
if (!$res) {
    die("connection false\n");
}
printf("--------- %d  ---------\n", __LINE__);
$testChannel = new AMQPChannel($rabbit);
printf("--------- %d  ---- Queue-----\n", __LINE__);
$q2 = new AMQPQueue($testChannel);
printf("--------- %d  ---- Exchange -----\n", __LINE__);
$testExchange = new AMQPExchange($testChannel);
printf("--------- %d  ---------\n", __LINE__);
$testExchange->setName('test_e2');
// $testExchange->delete();
$testExchange->setType('direct');
printf("--------- %d  ---------\n", __LINE__);
$testExchange->declare();
printf("--------- %d  ---------\n", __LINE__);
// unset($testChannel);
// printf("--------- %d  ---------\n", __LINE__);
// $testChannel = new AMQPChannel($rabbit);
printf("--------- %d  ---- Queue-----\n", __LINE__);
$q = new AMQPQueue($testChannel);
printf("--------- %d  ---------\n", __LINE__);
$q->setName('test_q');
printf("--------- %d  ---------\n", __LINE__);
$q->declare();
printf("--------- %d  ---------\n", __LINE__);
$q->bind('test_e', 'scan');
printf("--------- %d  ---------\n", __LINE__);
$rabbit->disconnect();
开发者ID:akalend,项目名称:hhvm-amqp,代码行数:31,代码来源:declare_queue.php

示例11: writeRMQ

/**
 * 批量打入v3work_seo_pdrec数据,用于预热本企业推荐产品
 */
function writeRMQ($exchangeName = 'v3cb', $routingKey, $data = '')
{
    global $cfg;
    if (empty($exchangeName) || empty($data) || empty($cfg)) {
        return false;
    }
    $reTryNum = 3;
    $errMsg = array();
    do {
        try {
            //建立到rmq服务器链接
            $connection = new AMQPConnection($cfg);
            $connection->connect();
            //建立channel对象
            $channel = new AMQPChannel($connection);
            //建立交换机
            $exchange = new AMQPExchange($channel);
            $exchange->setName($exchangeName);
            $exchange->setType(AMQP_EX_TYPE_DIRECT);
            $exchange->setFlags(AMQP_DURABLE);
            $exchange->declare();
            //发消息
            $ret = $exchange->publish($data, $routingKey, AMQP_NOPARAM, array('delivery_mode' => '2'));
            //关闭链接
            $connection->disconnect();
            return $ret;
        } catch (Exception $e) {
            $connection->disconnect();
            $errMsg[] = $e->getMessage();
            usleep(5000);
            $reTryNum -= 1;
        }
    } while ($reTryNum);
    return false;
}
开发者ID:tianyunchong,项目名称:php,代码行数:38,代码来源:comdetailseo.php

示例12: AMQPConnection

<?php

// print_r( get_loaded_extensions() );
$cnn = new AMQPConnection();
echo "------  connect ...  --------\n";
$ret = $cnn->connect();
echo "------  connect Ok  --------\n";
$ch = new AMQPChannel($cnn);
$ex = new AMQPExchange($ch);
$q = new AMQPQueue($ch);
echo "------  exchange Ok  --------\n";
// $cnn->disconnect(AMQP_NOPARAM);
$ex->setName('test_e');
$ex->setType(AMQP::TYPE_DIRECT);
$ex->declare();
echo "------  declare Ok  --------\n";
$q->setName('test_q');
$q->declare();
$res = $ex->bind("test_q", "kkk");
echo "------  binding Ok  --------\n";
var_dump($res);
$cnn->disconnect();
开发者ID:akalend,项目名称:hhvm-amqp,代码行数:22,代码来源:declare_exchange.php

示例13: declareExchange

 /**
  * Declares an exchange on the broker
  *
  * available options:
  *
  * - type: string
  * - passive: boolean
  * - durable: boolean
  * - auto_delete: boolean
  * - internal: boolean
  *
  * @param string $name
  * @param array $options
  *
  * @return CakeAmqpBase
  */
 public function declareExchange($name, $options = array())
 {
     if (!$this->connected()) {
         throw new CakeException(__d('cake_amqp', 'Not connected to broker'));
     }
     if (isset($this->_exchanges[$name])) {
         throw new CakeException(__d('cake_amqp', 'Exchange already exists: %s', $name));
     }
     $defaults = array('type' => 'direct', 'passive' => false, 'durable' => false, 'auto_delete' => true, 'internal' => false);
     $options = array_merge($defaults, $options);
     if (!array_key_exists($options['type'], $this->_exchangeTypes)) {
         throw new CakeException(__d('cake_amqp', 'Exchange type not supported: %s', $options['type']));
     }
     $exchange = new AMQPExchange($this->_channel);
     $exchange->setName($name);
     $exchange->setType($this->_exchangeTypes[$options['type']]);
     $exchange->setFlags($this->__getExchangeFlags($options));
     $exchange->declare();
     $this->_exchanges[$name] = $exchange;
     return $this;
 }
开发者ID:jellehenkens,项目名称:CakeAmqp,代码行数:37,代码来源:CakeAmqpBase.php


注:本文中的AMQPExchange::declare方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。