diff --git a/docs/transport/gps.md b/docs/transport/gps.md index 0ed47afe5..b56f5c949 100644 --- a/docs/transport/gps.md +++ b/docs/transport/gps.md @@ -62,21 +62,6 @@ $context->declareTopic($fooTopic); $context->createProducer()->send($fooTopic, $message); ``` -You can send attributes using headers : - -```php -createTopic('foo'); -$attributes = ['key1' => 'value1']; -$message = $context->createMessage('Hello world!', [], ['attributes' => $attributes]); - -$context->declareTopic($fooTopic); - -$context->createProducer()->send($fooTopic, $message); -``` - ## Consume message: Before you can consume message you have to subscribe a queue to the topic. diff --git a/pkg/gps/GpsMessage.php b/pkg/gps/GpsMessage.php index e638c26ad..4fff14859 100644 --- a/pkg/gps/GpsMessage.php +++ b/pkg/gps/GpsMessage.php @@ -24,6 +24,11 @@ class GpsMessage implements Message, \JsonSerializable */ private $headers; + /** + * @var array + */ + private $attributes; + /** * @var bool */ @@ -34,18 +39,12 @@ class GpsMessage implements Message, \JsonSerializable */ private $nativeMessage; - /** - * @var array - */ - private $attributes; - - public function __construct(string $body = '', array $properties = [], array $headers = []) + public function __construct(string $body = '', array $properties = [], array $headers = [], array $attributes = []) { $this->body = $body; $this->properties = $properties; - $this->attributes = $headers['attributes'] ?? []; - unset($headers['attributes']); $this->headers = $headers; + $this->attributes = $attributes; $this->redelivered = false; } @@ -181,6 +180,11 @@ public function setNativeMessage(?GoogleMessage $message = null): void $this->nativeMessage = $message; } + public function setAttributes(array $attributes): void + { + $this->attributes = $attributes; + } + public function getAttributes(): array { return $this->attributes; diff --git a/pkg/gps/Tests/GpsMessageTest.php b/pkg/gps/Tests/GpsMessageTest.php index c78372e88..5b48ca0ca 100644 --- a/pkg/gps/Tests/GpsMessageTest.php +++ b/pkg/gps/Tests/GpsMessageTest.php @@ -73,7 +73,7 @@ public function testThrowIfMalformedJsonGivenOnUnsterilizedFromJson() public function testGetAttributes() { - $message = new GpsMessage('the body', [], ['attributes' => ['key1' => 'value1']]); + $message = new GpsMessage('the body', [], [], ['key1' => 'value1']); $attributes = $message->getAttributes(); diff --git a/pkg/gps/Tests/GpsProducerTest.php b/pkg/gps/Tests/GpsProducerTest.php index 5e42938a5..c7de83e44 100644 --- a/pkg/gps/Tests/GpsProducerTest.php +++ b/pkg/gps/Tests/GpsProducerTest.php @@ -35,8 +35,7 @@ public function testShouldSendMessage() ->method('publish') ->with($this->identicalTo([ 'data' => '{"body":"","properties":[],"headers":[]}', - ]) - ); + ])); $client = $this->createPubSubClientMock(); $client @@ -60,7 +59,7 @@ public function testShouldSendMessage() public function testShouldSendMessageWithAttributes() { $topic = new GpsTopic('topic-name'); - $message = new GpsMessage('', [], ['attributes' => ['key1' => 'value1']]); + $message = new GpsMessage('', [], [], ['key1' => 'value1']); $gtopic = $this->createGTopicMock(); $gtopic