Skip to content

Commit 8495deb

Browse files
committed
Don't send attributes if it's empty
1 parent 46929e0 commit 8495deb

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

pkg/gps/GpsProducer.php

+8-4
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,14 @@ public function send(Destination $destination, Message $message): void
3737

3838
/** @var Topic $topic */
3939
$topic = $this->context->getClient()->topic($destination->getTopicName());
40-
$topic->publish([
41-
'data' => json_encode($message),
42-
'attributes' => $message->getAttributes(),
43-
]);
40+
41+
$params = ['data' => json_encode($message)];
42+
43+
if (count($message->getAttributes()) > 0) {
44+
$params['attributes'] = $message->getAttributes();
45+
}
46+
47+
$topic->publish($params);
4448
}
4549

4650
public function setDeliveryDelay(?int $deliveryDelay = null): Producer

pkg/gps/Tests/GpsProducerTest.php

-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ public function testShouldSendMessage()
3535
->method('publish')
3636
->with($this->identicalTo([
3737
'data' => '{"body":"","properties":[],"headers":[]}',
38-
'attributes' => [],
3938
])
4039
);
4140

0 commit comments

Comments
 (0)