public function publish($message, $routing_key, Properties $properties = null, $flags = AMQP_NOPARAM) { $content_type = 'text/plain'; $attributes = []; if ($properties) { if ($properties->getContentType()) { $content_type = $properties->getContentType(); } $attributes = $properties->toArray(); } $message = $this->serializers->get($content_type)->serialize($message); $attributes['content_type'] = $content_type; $attributes = array_filter($attributes); $this->exchange->publish($message, $routing_key, $flags, $attributes); }
/** * @covers AMQPy\Client\Properties::fromArray * @covers AMQPy\Client\Properties::toArray */ public function testFromAndToArray() { $empty = ['content_type' => null, 'content_encoding' => null, 'headers' => [], 'delivery_mode' => null, 'priority' => null, 'correlation_id' => null, 'reply_to' => null, 'expiration' => null, 'message_id' => null, 'timestamp' => null, 'type' => null, 'user_id' => null, 'app_id' => null]; $this->assertSame($empty, $this->object->toArray()); $this->object->fromArray([]); $this->assertSame($empty, $this->object->toArray()); $in = ['content_type' => 'contentType', 'content_encoding' => 'contentEncoding', 'headers' => ['headers' => 'value'], 'delivery_mode' => 'deliveryMode', 'priority' => 'priority', 'correlation_id' => 'correlationId', 'reply_to' => 'replyTo', 'expiration' => 'expiration', 'message_id' => 'messageId', 'timestamp' => 'timestamp', 'type' => 'type', 'user_id' => 'userId', 'app_id' => 'appId']; $in_with_nonexistent = $in; $in_with_nonexistent['nonexistent'] = 'Born to be wild'; $this->object->fromArray($in); $this->assertEquals($in, $this->object->toArray()); $this->object->fromArray([]); $this->assertSame($in, $this->object->toArray()); }
/** * @param array | \Traversable $headers */ public function setHeaders($headers) { $this->properties->setHeaders($headers); }