本文整理汇总了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));
}
示例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);
}
示例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');
}
示例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);
}
}
示例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);
}
}
示例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;
}
示例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;
}
示例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();
示例9: bind
/**
* @inheritdoc
*/
public function bind(string $exchangeName, string $routingKey = '', array $arguments = [])
{
$this->exchange->bind($exchangeName, $routingKey, $arguments);
}