/** * @test getPublishAttributes get properties from message */ public function publishAttributesFromMessage() { $message = $this->getMock('EventBand\\Transport\\Amqp\\Driver\\AmqpMessage'); $properties = ['headers' => ['x-header-1' => 'value1', 'x-header-2' => 'value2'], 'contentType' => 'application/json', 'contentEncoding' => 'utf-8', 'messageId' => '100', 'appId' => '2', 'userId' => '10', 'priority' => 3, 'timestamp' => strtotime('2012-12-18 09:45:11'), 'expiration' => 1000, 'type' => 'type_str', 'replyTo' => 'foo.bar']; foreach ($properties as $property => $value) { $message->expects($this->any())->method('get' . ucfirst($property))->will($this->returnValue($value)); } $attributes = PeclMessageUtils::getPublishAttributes($message); $this->assertEquals($properties['headers'], $attributes['headers']); $this->assertEquals($properties['contentType'], $attributes['content_type']); $this->assertEquals($properties['contentEncoding'], $attributes['content_encoding']); $this->assertEquals($properties['messageId'], $attributes['message_id']); $this->assertEquals($properties['appId'], $attributes['app_id']); $this->assertEquals($properties['userId'], $attributes['user_id']); $this->assertEquals($properties['priority'], $attributes['priority']); $this->assertEquals($properties['timestamp'], $attributes['timestamp']); $this->assertEquals($properties['expiration'], $attributes['expiration']); $this->assertEquals($properties['type'], $attributes['type']); $this->assertEquals($properties['replyTo'], $attributes['reply_to']); }
/** * {@inheritDoc} */ public function consume($queue, callable $callback, $timeout) { $oldTimeout = $this->connection->getReadTimeout(); $this->connection->setReadTimeout($timeout); try { $this->getQueue($queue)->consume(function (\AMQPEnvelope $envelope) use($callback, $queue) { return call_user_func($callback, PeclMessageUtils::createDelivery($envelope, $queue)); }); $this->connection->setReadTimeout($oldTimeout); $this->closeChannel(); } catch (\AMQPConnectionException $e) { $this->connection->setReadTimeout($oldTimeout); $expectedErrors = array('interrupted system call', 'resource temporarily unavailable'); foreach ($expectedErrors as $expectedError) { if (stripos($e->getMessage(), $expectedError) !== false) { return; } } throw new DriverException('Unexpected error while consuming', $e); } }