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


PHP AMQPExchange::bind方法代码示例

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


在下文中一共展示了AMQPExchange::bind方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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));
 }
开发者ID:JasonOcean,项目名称:iOS_Interest_Group,代码行数:27,代码来源:amqp_ut.php

示例2: 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

示例3: 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

示例4: bind

 /**
  * @param Exchange|string $exchange
  * @param string          $routingKey
  * @param array           $arguments
  *
  * @return bool
  */
 public function bind($exchange, $routingKey = '', array $arguments = [])
 {
     $exchange = AmqpHelper::getExchangeName($exchange);
     try {
         return $this->rawExchange->bind($exchange, $routingKey, $arguments);
     } catch (\Exception $e) {
         ClientHelper::throwRightException($e);
     }
 }
开发者ID:csharpru,项目名称:yii2-amqp,代码行数:16,代码来源:Exchange.php

示例5: bind

 /**
  * @inheritdoc
  */
 public function bind($exchangeName, $routingKey, array $arguments = [])
 {
     try {
         return $this->delegate->bind($exchangeName, $routingKey, $arguments);
     } catch (\AMQPExchangeException $e) {
         throw new ExchangeException($e->getMessage(), $e->getCode(), $e);
     } catch (\AMQPChannelException $e) {
         throw new ChannelException($e->getMessage(), $e->getCode(), $e);
     } catch (\AMQPConnectionException $e) {
         throw new ConnectionException($e->getMessage(), $e->getCode(), $e);
     }
 }
开发者ID:treehouselabs,项目名称:queue,代码行数:15,代码来源:Exchange.php

示例6: exchangeDeclare

 protected function exchangeDeclare()
 {
     if ($this->exchange === null) {
         $this->exchange = new AMQPExchange($this->channel);
     }
     $this->exchange->setName($this->exchangeOptions['name']);
     $this->exchange->setType($this->exchangeOptions['type']);
     $this->exchange->setFlags($this->getFlagsFromOptions());
     $this->exchange->setArguments($this->exchangeOptions['arguments']);
     $this->exchange->declareExchange();
     foreach ($this->exchangeOptions['binding'] as $bindOpt) {
         $this->exchange->bind($bindOpt['name'], $bindOpt['routing-keys']);
     }
     $this->exchangeDeclared = true;
 }
开发者ID:umpirsky,项目名称:ko-worker,代码行数:15,代码来源:Producer.php

示例7: getExchange

 /**
  * Get exchange
  *
  * @param string $name The exchange name
  *
  * @return \AMQPExchange
  */
 protected function getExchange($name)
 {
     if (isset($this->exchanges[$name])) {
         return $this->exchanges[$name];
     }
     $config = $this->getConfig('exchange', $name);
     if (null === $config) {
         throw new \InvalidArgumentException("Exchange definition '{$name}' doesn't exists.");
     }
     $connection = $this->getConnection($config['connection']);
     $this->exchanges[$name] = $exchange = new \AMQPExchange($connection['channel']);
     $exchange->setName(is_callable($config['name']) ? call_user_func($config['name']) : $config['name']);
     $exchange->setType(isset($config['type']) ? $config['type'] : 'topic');
     $exchange->setFlags(Helper\Options::toFlags($config));
     $exchange->declareExchange();
     if (isset($config['bindings'])) {
         foreach ($config['bindings'] as $binding) {
             try {
                 $this->getExchange($binding['exchange']);
             } catch (\InvalidArgumentException $e) {
             }
             $exchange->bind($binding['exchange'], $binding['routing_key'], isset($binding['arguments']) ? $binding['arguments'] : []);
         }
     }
     if (isset($config['arguments'])) {
         $exchange->setArguments($config['arguments']);
     }
     return $exchange;
 }
开发者ID:skatrych,项目名称:amqp-base,代码行数:36,代码来源:ExtAdapter.php

示例8: 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

示例9: bind

 /**
  * @inheritdoc
  */
 public function bind(string $exchangeName, string $routingKey = '', array $arguments = [])
 {
     $this->exchange->bind($exchangeName, $routingKey, $arguments);
 }
开发者ID:prolic,项目名称:HumusAmqp,代码行数:7,代码来源:Exchange.php


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