/** * 创建新队列 */ public function createQueue($queueName) { $queueAttributes = new QueueAttributes(); $queueAttributes->setPollingWaitSeconds(self::POLLING_WAITING_SECONDS); $queueAttributes->setVisibilityTimeout(self::VISIBILITY_TIMEOUT); $request = new CreateQueueRequest($queueName, $queueAttributes); try { $this->client->createQueue($request); } catch (MnsException $e) { throw new \Exception('创建队列失败'); } }
public function testCreateQueueSync() { $queueName = "testCreateQueueSync"; // 1. create queue with InvalidArgument $attributes = new QueueAttributes(); $attributes->setPollingWaitSeconds(60); $request = new CreateQueueRequest($queueName, $attributes); try { $res = $this->client->createQueue($request); $this->assertTrue(FALSE, "Should throw InvalidArgumentException"); } catch (MnsException $e) { $this->assertEquals($e->getMnsErrorCode(), Constants::INVALID_ARGUMENT); } // 2. create queue $request = new CreateQueueRequest($queueName); $this->queueToDelete[] = $queueName; try { $res = $this->client->createQueue($request); $this->assertTrue($res->isSucceed()); } catch (MnsException $e) { $this->assertTrue(FALSE, $e); } // 3. create queue with same attributes $request = new CreateQueueRequest($queueName); $this->queueToDelete[] = $queueName; try { $res = $this->client->createQueue($request); $this->assertTrue($res->isSucceed()); } catch (MnsException $e) { $this->assertTrue(FALSE, $e); } // 4. create same queue with different attributes $attributes = new QueueAttributes(); $attributes->setPollingWaitSeconds(20); $request = new CreateQueueRequest($queueName, $attributes); try { $res = $this->client->createQueue($request); $this->assertTrue(FALSE, "Should throw QueueAlreadyExistException"); } catch (MnsException $e) { $this->assertEquals($e->getMnsErrorCode(), Constants::QUEUE_ALREADY_EXIST); } }