Skip to content

Commit

Permalink
Don't send attributes if it's empty
Browse files Browse the repository at this point in the history
  • Loading branch information
p-pichet committed Jul 12, 2024
1 parent 46929e0 commit 8495deb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
12 changes: 8 additions & 4 deletions pkg/gps/GpsProducer.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,14 @@ public function send(Destination $destination, Message $message): void

/** @var Topic $topic */
$topic = $this->context->getClient()->topic($destination->getTopicName());
$topic->publish([
'data' => json_encode($message),
'attributes' => $message->getAttributes(),
]);

$params = ['data' => json_encode($message)];

if (count($message->getAttributes()) > 0) {
$params['attributes'] = $message->getAttributes();
}

$topic->publish($params);
}

public function setDeliveryDelay(?int $deliveryDelay = null): Producer
Expand Down
1 change: 0 additions & 1 deletion pkg/gps/Tests/GpsProducerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public function testShouldSendMessage()
->method('publish')
->with($this->identicalTo([
'data' => '{"body":"","properties":[],"headers":[]}',
'attributes' => [],
])
);

Expand Down

0 comments on commit 8495deb

Please sign in to comment.