本文整理汇总了PHP中AMQPQueue::setFlags方法的典型用法代码示例。如果您正苦于以下问题:PHP AMQPQueue::setFlags方法的具体用法?PHP AMQPQueue::setFlags怎么用?PHP AMQPQueue::setFlags使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AMQPQueue
的用法示例。
在下文中一共展示了AMQPQueue::setFlags方法的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
public function declareQueue($name, $flags = AMQP_DURABLE)
{
$queue = new \AMQPQueue($this->channel);
$queue->setName($name);
$queue->setFlags($flags);
$queue->declareQueue();
return $queue;
}
示例4: createQueue
/**
* @inheritdoc
*/
public function createQueue(ChannelInterface $channel, $name = null, $flags = null, array $args = [])
{
$delegate = new \AMQPQueue($channel->getDelegate());
$delegate->setFlags(Queue::convertToDelegateFlags($flags));
$delegate->setArguments($args);
if (null !== $name) {
$delegate->setName($name);
}
return new Queue($delegate, $channel);
}
示例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: 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);
}
示例8: _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;
}
示例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: 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);
}
}
示例11: 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];
}
示例12: 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;
}
示例13: main
public static function main()
{
self::$pool = new Pool(MAX_CONCURRENCY_JOB, \CALLWorker::class, []);
$conn_args = (require 'mq.config.php');
$e_name = 'e_linvo';
//交换机名
$q_name = 'q_linvo';
//队列名
$k_route = 'key_1';
//路由key
//创建连接和channel
$conn = new AMQPConnection($conn_args);
if (!$conn->connect()) {
write_log('mq.hx9999.com 无法连接上');
return;
}
$channel = new AMQPChannel($conn);
//创建交换机
$ex = new AMQPExchange($channel);
$ex->setName($e_name);
$ex->setType(AMQP_EX_TYPE_DIRECT);
//direct类型
$ex->setFlags(AMQP_DURABLE);
//持久化
//创建队列
$q = new AMQPQueue($channel);
$q->setName($q_name);
$q->setFlags(AMQP_DURABLE);
//持久化
while (True) {
$q->consume(function ($envelope, $queue) {
$msg = $envelope->getBody();
$queue->ack($envelope->getDeliveryTag());
//手动发送ACK应答
self::$pool->submit(new Sendsms($msg));
});
}
self::$pool->shutdown();
$conn->disconnect();
//睡眠
sleep(5);
}
示例14: 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.!");
}
}
示例15: 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());
}