本文整理汇总了PHP中AMQPQueue::bind方法的典型用法代码示例。如果您正苦于以下问题:PHP AMQPQueue::bind方法的具体用法?PHP AMQPQueue::bind怎么用?PHP AMQPQueue::bind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AMQPQueue
的用法示例。
在下文中一共展示了AMQPQueue::bind方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _initPublisher
private function _initPublisher()
{
if (!$this->open()) {
return false;
}
if ($this->_exchange) {
return true;
}
$channel = new AMQPChannel($this->_conn);
//创建exchange
$this->_exchange = new AMQPExchange($channel);
$this->_exchange->setName($this->_connInfo['exchangeName']);
$this->_exchange->setType(AMQP_EX_TYPE_DIRECT);
$this->_exchange->setFlags(AMQP_DURABLE);
if (!$this->_exchange->declareExchange()) {
$this->close();
return false;
}
//创建队列,生产者和消费者都要创建队列
$queue = new AMQPQueue($channel);
$queue->setName($this->_connInfo['queueName']);
$queue->setFlags(AMQP_DURABLE);
$queue->declareQueue();
$queue->bind($this->_connInfo['exchangeName'], $this->_connInfo['routingKey']);
return true;
}
示例2: receive
/**
* {@inheritDoc}
*/
public function receive(array $eventNames, \Closure $callback)
{
$exchangeName = $this->exchange->getName();
foreach ($eventNames as $eventName) {
$this->queue->bind($exchangeName, $eventName);
}
$this->queue->consume(function (\AMQPEnvelope $envelope, \AMQPQueue $queue) use($callback) {
$message = $envelope->getBody();
$messageTag = $envelope->getDeliveryTag();
$status = call_user_func($callback, $message);
if ($status) {
$queue->ack($messageTag);
} else {
$queue->nack($messageTag);
}
});
}
示例3: bind
/**
* Bind queue to exchange using dispatcher event names as routing keys
*
* @return void
* @throws AMQPExchangeException
*/
public function bind(\AMQPQueue $queue, \AMQPExchange $exchange)
{
$events = preg_grep($this->pattern, array_keys($this->getDispatcher()->getListeners()));
foreach ($events as $eventName) {
$queue->bind($exchange->getName(), $eventName);
}
$this->dispatcher->dispatch(static::BIND_EVENT, new SymfonyEvent($events, ["pattern" => $this->pattern, "exchange" => $exchange->getName(), "queue" => $queue->getName()]));
}
示例4: bind
/**
* @param Exchange|string $exchange
* @param string $routingKey
* @param array $arguments
*
* @return bool
*/
public function bind($exchange, $routingKey = null, array $arguments = [])
{
$exchange = AmqpHelper::getExchangeName($exchange);
try {
return $this->rawQueue->bind($exchange, $routingKey, $arguments);
} catch (\Exception $e) {
ClientHelper::throwRightException($e);
}
}
示例5: 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;
}
示例6: it_should_initialize
public function it_should_initialize(\AMQPQueue $queue, Exchange $exchange, Context $context)
{
$exchange->getName()->willReturn('exchange');
$context->getFlags()->willReturn(1234);
$context->getArguments()->willReturn(['foo' => 'bar']);
$queue->setName('queue')->shouldBeCalled();
$queue->bind('exchange')->shouldBeCalled();
$queue->setFlags(1234)->shouldBeCalled();
$queue->setArguments(['foo' => 'bar'])->shouldBeCalled();
$queue->declareQueue()->shouldBeCalled();
$this->initialize($queue);
$this->isInitialized()->shouldReturn(true);
}
示例7: _getQueue
/**
* Get transport queue for current channel.
* @return AMQPQueue
*/
protected function _getQueue()
{
if (!$this->_queue) {
//创建队列
$this->_queue = new \AMQPQueue($this->_getChannel());
//设置队列名字 如果不存在则添加
$this->_queue->setName($this->_params['queue']);
$this->_queue->setFlags(AMQP_DURABLE | AMQP_AUTODELETE);
$this->_queue->declareQueue();
//将你的队列绑定到routingKey
$this->_queue->bind($this->_params['exchange'], $this->_params['router']);
}
return $this->_queue;
}
示例8: subscribe
public function subscribe($topic, $queueName, $process_callback)
{
$channel = new AMQPChannel($this->amqpConnection);
$channel->setPrefetchCount(0);
$queue = new AMQPQueue($channel);
$queue->setName($queueName);
$queue->setFlags(AMQP_DURABLE);
$queue->declareQueue();
$queue->bind('topic', $topic);
$queue->consume($process_callback);
if (!$this->amqpConnection->disconnect()) {
throw new Exception("Could not disconnect !");
}
}
示例9: 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);
}
}
示例10: setUpAmqp
/**
* {@inheritDoc}
*/
protected function setUpAmqp()
{
$this->conn = new \AMQPConnection(['host' => $_SERVER['AMQP_HOST'], 'port' => $_SERVER['AMQP_PORT'], 'login' => $_SERVER['AMQP_USER'], 'password' => $_SERVER['AMQP_PASS'], 'vhost' => $_SERVER['AMQP_VHOST']]);
$this->conn->connect();
$channel = new \AMQPChannel($this->conn);
$exchange = new \AMQPExchange($channel);
$exchange->setName('event_band.test.exchange');
$exchange->setFlags(AMQP_AUTODELETE);
$exchange->setType(AMQP_EX_TYPE_TOPIC);
$exchange->declareExchange();
$queue = new \AMQPQueue($channel);
$queue->setName('event_band.test.event');
$queue->declareQueue();
$queue->bind('event_band.test.exchange', 'event.#');
}
示例11: initialize
/**
* @param \AMQPQueue|null $queue
*
* @throws HectorException
*/
public function initialize(\AMQPQueue $queue = null)
{
if (true === $this->isInitialized()) {
throw new HectorException('Queue already initialized');
}
if (null === $queue) {
$queue = new \AMQPQueue($this->channel->getWrappedChannel());
}
$this->queue = $queue;
$this->queue->setName($this->getName());
$this->queue->bind($this->exchange->getName());
$this->queue->setFlags($this->context->getFlags());
$this->queue->setArguments($this->context->getArguments());
$this->queue->declareQueue();
$this->initialized = true;
}
示例12: send
public function send($msg)
{
$channel = new \AMQPChannel($this->connection);
$exchange = new \AMQPExchange($channel);
$exchange->setFlags(AMQP_DURABLE);
$exchange->setName('exchange2');
$exchange->setType('direct');
//$exchange->declare();
$exchange->declareExchange();
$queue = new \AMQPQueue($channel);
$queue->setName('series');
$queue->setFlags(AMQP_DURABLE | AMQP_AUTODELETE);
//$queue->declare();
$queue->declareQueue();
$queue->bind('exchange2', 'series');
$channel->startTransaction();
$message = $exchange->publish(json_encode($msg), 'series', AMQP_MANDATORY, array('content_type' => 'application/json', 'delivery_mode' => 2));
$channel->commitTransaction();
if (!$message) {
throw new \SYSTEM\LOG\ERROR("Error: Message '" . $message . "' was not sent to queue.!");
}
}
示例13: GetMessageBody
/**
* Return result of task execution for $task_id
* @param AMQPConnection $connection Connection object
* @param string $task_id Celery task identifier
* @param boolean $removeMessageFromQueue whether to remove message from queue
* @return array array('body' => JSON-encoded message body, 'complete_result' => AMQPEnvelope object)
* or false if result not ready yet
*/
function GetMessageBody($connection, $task_id, $removeMessageFromQueue = true)
{
$this->Connect($connection);
$ch = $connection->channel;
$q = new AMQPQueue($ch);
$q->setName($task_id);
$q->setFlags(AMQP_AUTODELETE | AMQP_DURABLE);
$q->declareQueue();
try {
$q->bind('celeryresults', $task_id);
} catch (AMQPQueueException $e) {
if ($removeMessageFromQueue) {
$q->delete();
}
$connection->disconnect();
return false;
}
$message = $q->get(AMQP_AUTOACK);
if (!$message) {
if ($removeMessageFromQueue) {
$q->delete();
}
$connection->disconnect();
return false;
}
if ($message->getContentType() != 'application/json') {
if ($removeMessageFromQueue) {
$q->delete();
}
$connection->disconnect();
throw new CeleryException('Response was not encoded using JSON - found ' . $message->getContentType() . ' - check your CELERY_RESULT_SERIALIZER setting!');
}
if ($removeMessageFromQueue) {
$q->delete();
}
$connection->disconnect();
return array('complete_result' => $message, 'body' => $message->getBody());
}
示例14: set
/**
* 入RabbitMQ队列
* @param [type] $exName [交换机名]
* @param [type] $routingKey [路由名]
* @param [type] $value [队列的值]
* @param [type] $dbType [数据库类型,默认为mysql]
* 按照此规则生成的默认队列名称为 exName_routeKey_dbType;值为value
*/
public function set($exName, $routingKey, $value, $dbType = 'mysql')
{
//创建交换机,设置交换机名
$ex = new \AMQPExchange($this->channel);
$ex->setName($exName);
$ex->setType(AMQP_EX_TYPE_DIRECT);
//广播模式
$ex->setFlags(AMQP_DURABLE);
//交换器进行持久化,即 RabbitMQ 重启后会自动重建
// $ex->declareExchange();
//设置队列名
$queue = new \AMQPQueue($this->channel);
$queue->setName($exName . '_' . $routingKey . '_' . $dbType);
$queue->setFlags(AMQP_DURABLE);
//队列进行持久化,即 RabbitMQ 重启后会自动重建
$queue->declareQueue();
//交换机和路由绑定到队列
$queue->bind($exName, $routingKey);
//入队列
if (is_array($value)) {
$value = json_encode($value);
}
$ex->publish($value, $routingKey, AMQP_NOPARAM, array('delivery_mode' => '2'));
}
示例15: getCompleteResult
/**
* Connect to queue, see if there's a result waiting for us
* Private - to be used internally
*/
private function getCompleteResult()
{
if ($this->complete_result) {
return $this->complete_result;
}
$this->connection->connect();
$ch = new AMQPChannel($this->connection);
$q = new AMQPQueue($ch);
$q->setName($this->task_id);
$q->setFlags(AMQP_AUTODELETE);
# $q->setArgument('x-expires', 86400000);
$q->declareQueue();
try {
$q->bind('celeryresults', $this->task_id);
} catch (AMQPQueueException $e) {
$q->delete();
$this->connection->disconnect();
return false;
}
$message = $q->get(AMQP_AUTOACK);
if (!$message) {
$q->delete();
$this->connection->disconnect();
return false;
}
$this->complete_result = $message;
if ($message->getContentType() != 'application/json') {
$q->delete();
$this->connection->disconnect();
throw new CeleryException('Response was not encoded using JSON - found ' . $message->getContentType() . ' - check your CELERY_RESULT_SERIALIZER setting!');
}
$this->body = json_decode($message->getBody());
$q->delete();
$this->connection->disconnect();
return false;
}