/** * {@inheritDoc} */ public function publish(MessagePublication $publication, $exchange, $routingKey = '') { try { $this->getChannel()->basic_publish(AmqpMessageUtils::createAmqpLibMessage($publication->getMessage(), $publication->isPersistent()), $exchange, $routingKey, $publication->isMandatory(), $publication->isImmediate()); } catch (\Exception $e) { throw new DriverException('Basic publish error', $e); } }
/** * @test createAmqpLibMessage copy properties from driver message to amqp lib message one */ public function copyPropertiesToAmqpLib() { $properties = ['body' => 'body content', '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']; $message = $this->createMessage($properties); $amqpLibMessage = AmqpMessageUtils::createAmqpLibMessage($message); $this->assertEquals('body content', $amqpLibMessage->body); $this->assertEquals($properties['headers'], $amqpLibMessage->get('application_headers')); $this->assertEquals($properties['contentType'], $amqpLibMessage->get('content_type')); $this->assertEquals($properties['contentEncoding'], $amqpLibMessage->get('content_encoding')); $this->assertEquals($properties['messageId'], $amqpLibMessage->get('message_id')); $this->assertEquals($properties['appId'], $amqpLibMessage->get('app_id')); $this->assertEquals($properties['userId'], $amqpLibMessage->get('user_id')); $this->assertEquals($properties['priority'], $amqpLibMessage->get('priority')); $this->assertEquals($properties['timestamp'], $amqpLibMessage->get('timestamp')); $this->assertEquals($properties['expiration'], $amqpLibMessage->get('expiration')); $this->assertEquals($properties['type'], $amqpLibMessage->get('type')); $this->assertEquals($properties['replyTo'], $amqpLibMessage->get('reply_to')); }