/** * @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 publish(MessagePublication $publication, $exchange, $routingKey = '') { $flags = AMQP_NOPARAM; if ($publication->isImmediate()) { $flags |= AMQP_IMMEDIATE; } if ($publication->isMandatory()) { $flags |= AMQP_MANDATORY; } $this->getExchange($exchange)->publish($publication->getMessage()->getBody(), $routingKey, $flags, PeclMessageUtils::getPublishAttributes($publication->getMessage())); }