From 8495deb8581c11cea0bcc855a58c2def9a9e360d Mon Sep 17 00:00:00 2001
From: philippe PICHET
Date: Fri, 5 Jul 2024 11:01:10 +0200
Subject: [PATCH] Don't send attributes if it's empty
---
pkg/gps/GpsProducer.php | 12 ++++++++----
pkg/gps/Tests/GpsProducerTest.php | 1 -
2 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/pkg/gps/GpsProducer.php b/pkg/gps/GpsProducer.php
index e2e6d4046..b36fad19d 100644
--- a/pkg/gps/GpsProducer.php
+++ b/pkg/gps/GpsProducer.php
@@ -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
diff --git a/pkg/gps/Tests/GpsProducerTest.php b/pkg/gps/Tests/GpsProducerTest.php
index a677e1328..5e42938a5 100644
--- a/pkg/gps/Tests/GpsProducerTest.php
+++ b/pkg/gps/Tests/GpsProducerTest.php
@@ -35,7 +35,6 @@ public function testShouldSendMessage()
->method('publish')
->with($this->identicalTo([
'data' => '{"body":"","properties":[],"headers":[]}',
- 'attributes' => [],
])
);