本文整理汇总了PHP中AMQPQueue::declareQueue方法的典型用法代码示例。如果您正苦于以下问题:PHP AMQPQueue::declareQueue方法的具体用法?PHP AMQPQueue::declareQueue怎么用?PHP AMQPQueue::declareQueue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AMQPQueue
的用法示例。
在下文中一共展示了AMQPQueue::declareQueue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getSrvQueue
/**
* @return \AMQPQueue
*/
public function getSrvQueue()
{
if ($this->srvQueue === null) {
$chanel = $this->getChanel();
/* create a queue object */
$this->srvQueue = new \AMQPQueue($chanel);
$this->srvQueue->setName($this->queueName);
$this->srvQueue->setFlags(AMQP_DURABLE);
$this->srvQueue->declareQueue();
}
return $this->srvQueue;
}
示例2: _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;
}
示例3: declareQueue
/**
* @return int
*/
public function declareQueue()
{
try {
return $this->rawQueue->declareQueue();
} catch (\Exception $e) {
ClientHelper::throwRightException($e);
}
}
示例4: declareQueue
public function declareQueue($name, $flags = AMQP_DURABLE)
{
$queue = new \AMQPQueue($this->channel);
$queue->setName($name);
$queue->setFlags($flags);
$queue->declareQueue();
return $queue;
}
示例5: declareResponseQueue
/**
* @param \AMQPExchange $exchange
* @return \AMQPQueue
*/
protected function declareResponseQueue(\AMQPExchange $exchange)
{
$queue = new \AMQPQueue($exchange->getChannel());
$queue->setFlags(AMQP_EXCLUSIVE);
if ($this->queueTimeout !== null) {
$queue->setArgument("x-expires", $this->queueTimeout);
}
$queue->declareQueue();
return $queue;
}
示例6: getQueue
/**
* @return \AMQPQueue
*/
protected function getQueue()
{
if (!$this->queue) {
$this->queue = new \AMQPQueue($this->getChannel());
$this->queue->setName($this->queueConfig['name']);
$this->queue->setFlags($this->queueConfig['flags']);
$this->queue->declareQueue();
}
return $this->queue;
}
示例7: declareQueue
/**
* @inheritdoc
*/
public function declareQueue() : int
{
try {
return $this->queue->declareQueue();
} catch (\AMQPQueueException $e) {
throw QueueException::fromAmqpExtension($e);
} catch (\AMQPChannelException $e) {
throw ChannelException::fromAmqpExtension($e);
}
}
示例8: 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);
}
示例9: 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 !");
}
}
示例10: _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;
}
示例11: 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.#');
}
示例12: setupConnection
public static function setupConnection(\AMQPConnection $connection, $config)
{
$channel = new \AMQPChannel($connection);
$exchange = new \AMQPExchange($channel);
$exchange->setName($config['exchange_name']);
$exchange->setType(AMQP_EX_TYPE_DIRECT);
$exchange->setFlags(AMQP_DURABLE);
$exchange->declareExchange();
$queue = new \AMQPQueue($channel);
$queue->setName($config['queue_name']);
$queue->setFlags(AMQP_DURABLE);
$queue->declareQueue();
// $exchange->bind($config['queue_name'], 'gos.websocket.pusher');
return [$channel, $exchange, $queue];
}
示例13: basic_consume
/**
* @param string $queue
* @param string $consumer_tag
* @param bool $no_local
* @param bool $no_ack
* @param bool $exclusive
* @param bool $nowait
* @param callable $callback
* @param string $ticket
* @param array $arguments
* @return mixed
*/
public function basic_consume($queue = '', $consumer_tag = '', $no_local = false, $no_ack = false, $exclusive = false, $nowait = false, callable $callback = null, $ticket = null, $arguments = array())
{
$q = new \AMQPQueue($this->channel);
$q->setName($queue);
$q->declareQueue();
$flags = AMQP_NOPARAM;
$flags += $no_local ? AMQP_NOLOCAL : 0;
$flags += $no_ack ? AMQP_AUTOACK : 0;
$flags += $exclusive ? AMQP_EXCLUSIVE : 0;
$flags += $nowait ? AMQP_NOWAIT : 0;
$q->consume(function ($message, \AMQPQueue $q) use($callback, $flags, $consumer_tag) {
$deliveryInfo = array('channel' => $q, 'delivery_tag' => '');
return $callback(new AMQPMessage($message, array(), $deliveryInfo));
}, $flags, $consumer_tag);
}
示例14: consume
public function consume($queueName, $callBackFunction)
{
try {
$queue = new AMQPQueue($this->channel);
$queue->setName($queueName);
$queue->setFlags(AMQP_DURABLE);
$queue->declareQueue();
echo ' [*] Waiting for messages on ' . $queueName . '. To exit press CTRL+C ', PHP_EOL;
$queue->consume($callBackFunction);
} catch (AMQPQueueException $ex) {
print_r($ex);
} catch (Exception $ex) {
print_r($ex);
}
}
示例15: 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;
}