Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9ce3f7c

Browse files
committed
Use a property attributes instead of a key in headers
1 parent d748405 commit 9ce3f7c

File tree

4 files changed

+14
-25
lines changed

4 files changed

+14
-25
lines changed

‎docs/transport/gps.md

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -62,21 +62,6 @@ $context->declareTopic($fooTopic);
6262
$context->createProducer()->send($fooTopic, $message);
6363
```
6464

65-
You can send attributes using headers :
66-
67-
```php
68-
<?php
69-
/** @var \Enqueue\Gps\GpsContext $context */
70-
71-
$fooTopic = $context->createTopic('foo');
72-
$attributes = ['key1' => 'value1'];
73-
$message = $context->createMessage('Hello world!', [], ['attributes' => $attributes]);
74-
75-
$context->declareTopic($fooTopic);
76-
77-
$context->createProducer()->send($fooTopic, $message);
78-
```
79-
8065
## Consume message:
8166

8267
Before you can consume message you have to subscribe a queue to the topic.

‎pkg/gps/GpsMessage.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ class GpsMessage implements Message, \JsonSerializable
2424
*/
2525
private $headers;
2626

27+
/**
28+
* @var array
29+
*/
30+
private $attributes;
31+
2732
/**
2833
* @var bool
2934
*/
@@ -34,18 +39,12 @@ class GpsMessage implements Message, \JsonSerializable
3439
*/
3540
private $nativeMessage;
3641

37-
/**
38-
* @var array
39-
*/
40-
private $attributes;
41-
42-
public function __construct(string $body = '', array $properties = [], array $headers = [])
42+
public function __construct(string $body = '', array $properties = [], array $headers = [], array $attributes = [])
4343
{
4444
$this->body = $body;
4545
$this->properties = $properties;
46-
$this->attributes = $headers['attributes'] ?? [];
47-
unset($headers['attributes']);
4846
$this->headers = $headers;
47+
$this->attributes = $attributes;
4948

5049
$this->redelivered = false;
5150
}
@@ -181,6 +180,11 @@ public function setNativeMessage(?GoogleMessage $message = null): void
181180
$this->nativeMessage = $message;
182181
}
183182

183+
public function setAttributes(array $attributes): void
184+
{
185+
$this->attributes = $attributes;
186+
}
187+
184188
public function getAttributes(): array
185189
{
186190
return $this->attributes;

‎pkg/gps/Tests/GpsMessageTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function testThrowIfMalformedJsonGivenOnUnsterilizedFromJson()
7373

7474
public function testGetAttributes()
7575
{
76-
$message = new GpsMessage('the body', [], ['attributes' => ['key1' => 'value1']]);
76+
$message = new GpsMessage('the body', [], [], ['key1' => 'value1']);
7777

7878
$attributes = $message->getAttributes();
7979

‎pkg/gps/Tests/GpsProducerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function testShouldSendMessage()
6060
public function testShouldSendMessageWithAttributes()
6161
{
6262
$topic = new GpsTopic('topic-name');
63-
$message = new GpsMessage('', [], ['attributes' => ['key1' => 'value1']]);
63+
$message = new GpsMessage('', [], [], ['key1' => 'value1']);
6464

6565
$gtopic = $this->createGTopicMock();
6666
$gtopic

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /