/** * Create a queue * * @param ServiceLocatorInterface $services * @param string $name * @param string $requestedName * @return Queue */ public function createServiceWithName(ServiceLocatorInterface $services, $name, $requestedName) { $config = $this->getConfig($services); $config = $config[$requestedName]; if (isset($config['adapter']) && is_string($config['adapter']) && $services->has($config['adapter'])) { $adapter = $services->get($config['adapter']); if ($adapter instanceof Adapter\AdapterInterface) { $config['adapter'] = $adapter; } } $queue = Queue::factory($config); return $queue; }
public function testConstruct() { $message = new Message(); $message->setContent('A message'); $stdMessage = new ZendMessage(); $stdMessage->setContent('A stdlib message'); //Test array of Message, without queue in constructor $messages = new MessageIterator([$message, $stdMessage]); $this->assertEquals($message, $messages->current()); $messages->next(); $this->assertEquals($stdMessage, $messages->current()); $this->assertNull($messages->getQueue()); $this->assertNull($messages->getQueueClass()); //Test array of array, without queue in constructor $messages = new MessageIterator([['content' => 'a message']]); $this->assertEquals('a message', $messages->current()->getContent()); $this->assertInstanceOf($this->queue->getOptions()->getMessageClass(), $messages->current()); //Test with queue in constructor $messages = new MessageIterator([$message, $stdMessage], $this->queue); $this->assertTrue($this->queue === $messages->getQueue()); $this->assertEquals(get_class($this->queue), $this->messages->getQueueClass()); }
public function testDefaultMessageClass() { $this->queue->send('testMessage'); $messages = $this->queue->receive(); $this->assertInstanceOf(Message::class, $messages->current()); }
/** * @param $info * @param Queue $queue */ protected function checkMessageInfo($info, Queue $queue) { $this->assertInternalType('array', $info); $this->assertArrayHasKey('adapter', $info); $this->assertSame(get_class($queue->getAdapter()), $info['adapter']); $this->assertArrayHasKey('queueName', $info); $this->assertSame($queue->getName(), $info['queueName']); }
public function testUsageExample() { // Create an array queue adapter $adapter = new ArrayAdapter(); // Create a queue object $queue = new Queue('queue1', $adapter); // Ensure queue1 exists in the backend $queue->ensureQueue(); // Create a new queue object $queue2 = new Queue('queue2', $adapter); // Ensure queue2 exists in the backend $queue2->ensureQueue(); // Get list of queues foreach ($adapter->listQueues() as $name) { $this->assertStringStartsWith('queue', $name); // echo $name, "\n"; } // Send a message to queue1 $queue->send('My Test Message'); // Get number of messages in a queue1 (supports Countable interface from SPL) $this->assertCount(1, $queue); //echo count($queue); // Get up to 5 messages from a queue1 $messages = $queue->receive(5); foreach ($messages as $i => $message) { $this->assertSame('My Test Message', $message->getContent()); //echo $message->getContent(), "\n"; // We have processed the message; now we remove it from the queue. $queue->delete($message); } // Delete a queue we created and all of it's messages $queue->deleteQueue(); }