From 805e3e62d3fad0c91673af5927c371285fcbcea0 Mon Sep 17 00:00:00 2001 From: philippe PICHET Date: Mon, 6 May 2024 11:25:31 +0200 Subject: [PATCH 01/17] feat(GPS): allow send attributes in Google PubSub message. --- docs/transport/gps.md | 15 +++++++++++++++ pkg/gps/GpsMessage.php | 22 +++++++++++++++++----- pkg/gps/GpsProducer.php | 7 ++++--- pkg/gps/Tests/GpsMessageTest.php | 11 ++++++++++- pkg/gps/Tests/GpsProducerTest.php | 31 +++++++++++++++++++++++++++++++ 5 files changed, 77 insertions(+), 9 deletions(-) diff --git a/docs/transport/gps.md b/docs/transport/gps.md index b56f5c949..0ed47afe5 100644 --- a/docs/transport/gps.md +++ b/docs/transport/gps.md @@ -62,6 +62,21 @@ $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 b4a11dc5a..e638c26ad 100644 --- a/pkg/gps/GpsMessage.php +++ b/pkg/gps/GpsMessage.php @@ -34,10 +34,17 @@ class GpsMessage implements Message, \JsonSerializable */ private $nativeMessage; + /** + * @var array + */ + private $attributes; + public function __construct(string $body = '', array $properties = [], array $headers = []) { $this->body = $body; $this->properties = $properties; + $this->attributes = $headers['attributes'] ?? []; + unset($headers['attributes']); $this->headers = $headers; $this->redelivered = false; @@ -103,7 +110,7 @@ public function isRedelivered(): bool return $this->redelivered; } - public function setCorrelationId(string $correlationId = null): void + public function setCorrelationId(?string $correlationId = null): void { $this->setHeader('correlation_id', $correlationId); } @@ -113,7 +120,7 @@ public function getCorrelationId(): ?string return $this->getHeader('correlation_id'); } - public function setMessageId(string $messageId = null): void + public function setMessageId(?string $messageId = null): void { $this->setHeader('message_id', $messageId); } @@ -130,12 +137,12 @@ public function getTimestamp(): ?int return null === $value ? null : (int) $value; } - public function setTimestamp(int $timestamp = null): void + public function setTimestamp(?int $timestamp = null): void { $this->setHeader('timestamp', $timestamp); } - public function setReplyTo(string $replyTo = null): void + public function setReplyTo(?string $replyTo = null): void { $this->setHeader('reply_to', $replyTo); } @@ -169,8 +176,13 @@ public function getNativeMessage(): ?GoogleMessage return $this->nativeMessage; } - public function setNativeMessage(GoogleMessage $message = null): void + public function setNativeMessage(?GoogleMessage $message = null): void { $this->nativeMessage = $message; } + + public function getAttributes(): array + { + return $this->attributes; + } } diff --git a/pkg/gps/GpsProducer.php b/pkg/gps/GpsProducer.php index 86c9052c0..e2e6d4046 100644 --- a/pkg/gps/GpsProducer.php +++ b/pkg/gps/GpsProducer.php @@ -39,10 +39,11 @@ public function send(Destination $destination, Message $message): void $topic = $this->context->getClient()->topic($destination->getTopicName()); $topic->publish([ 'data' => json_encode($message), + 'attributes' => $message->getAttributes(), ]); } - public function setDeliveryDelay(int $deliveryDelay = null): Producer + public function setDeliveryDelay(?int $deliveryDelay = null): Producer { if (null === $deliveryDelay) { return $this; @@ -56,7 +57,7 @@ public function getDeliveryDelay(): ?int return null; } - public function setPriority(int $priority = null): Producer + public function setPriority(?int $priority = null): Producer { if (null === $priority) { return $this; @@ -70,7 +71,7 @@ public function getPriority(): ?int return null; } - public function setTimeToLive(int $timeToLive = null): Producer + public function setTimeToLive(?int $timeToLive = null): Producer { if (null === $timeToLive) { return $this; diff --git a/pkg/gps/Tests/GpsMessageTest.php b/pkg/gps/Tests/GpsMessageTest.php index a43a22315..c78372e88 100644 --- a/pkg/gps/Tests/GpsMessageTest.php +++ b/pkg/gps/Tests/GpsMessageTest.php @@ -29,7 +29,7 @@ public function testCouldBeUnserializedFromJson() $json = json_encode($message); - //guard + // guard $this->assertNotEmpty($json); $unserializedMessage = GpsMessage::jsonUnserialize($json); @@ -70,4 +70,13 @@ public function testThrowIfMalformedJsonGivenOnUnsterilizedFromJson() GpsMessage::jsonUnserialize('{]'); } + + public function testGetAttributes() + { + $message = new GpsMessage('the body', [], ['attributes' => ['key1' => 'value1']]); + + $attributes = $message->getAttributes(); + + $this->assertSame(['key1' => 'value1'], $attributes); + } } diff --git a/pkg/gps/Tests/GpsProducerTest.php b/pkg/gps/Tests/GpsProducerTest.php index 1e1bfae41..9e39078e4 100644 --- a/pkg/gps/Tests/GpsProducerTest.php +++ b/pkg/gps/Tests/GpsProducerTest.php @@ -55,6 +55,37 @@ public function testShouldSendMessage() $producer->send($topic, $message); } + public function testShouldSendMessageWithAttributes() + { + $topic = new GpsTopic('topic-name'); + $message = new GpsMessage('', [], ['attributes' => ['key1' => 'value1']]); + + $gtopic = $this->createGTopicMock(); + $gtopic + ->expects($this->once()) + ->method('publish') + ->with($this->identicalTo(['data' => '{"body":"","properties":[],"headers":[]}', 'attributes' => ['key1' => 'value1']])) + ; + + $client = $this->createPubSubClientMock(); + $client + ->expects($this->once()) + ->method('topic') + ->with('topic-name') + ->willReturn($gtopic) + ; + + $context = $this->createContextMock(); + $context + ->expects($this->once()) + ->method('getClient') + ->willReturn($client) + ; + + $producer = new GpsProducer($context); + $producer->send($topic, $message); + } + /** * @return GpsContext|\PHPUnit\Framework\MockObject\MockObject|GpsContext */ From 46929e0e080f41f87cabae9d39ef0d0a9e9698d0 Mon Sep 17 00:00:00 2001 From: philippe PICHET Date: Tue, 2 Jul 2024 16:33:31 +0200 Subject: [PATCH 02/17] Fixing CI --- pkg/gps/Tests/GpsProducerTest.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pkg/gps/Tests/GpsProducerTest.php b/pkg/gps/Tests/GpsProducerTest.php index 9e39078e4..a677e1328 100644 --- a/pkg/gps/Tests/GpsProducerTest.php +++ b/pkg/gps/Tests/GpsProducerTest.php @@ -33,8 +33,11 @@ public function testShouldSendMessage() $gtopic ->expects($this->once()) ->method('publish') - ->with($this->identicalTo(['data' => '{"body":"","properties":[],"headers":[]}'])) - ; + ->with($this->identicalTo([ + 'data' => '{"body":"","properties":[],"headers":[]}', + 'attributes' => [], + ]) + ); $client = $this->createPubSubClientMock(); $client From 8495deb8581c11cea0bcc855a58c2def9a9e360d Mon Sep 17 00:00:00 2001 From: philippe PICHET Date: Fri, 5 Jul 2024 11:01:10 +0200 Subject: [PATCH 03/17] 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' => [], ]) ); From 076aeddbf317b2b5e3c3774db12342d28c6e0ede Mon Sep 17 00:00:00 2001 From: philippe PICHET Date: Thu, 1 Aug 2024 15:36:06 +0200 Subject: [PATCH 04/17] Set delevery tags on AMQP --- pkg/amqp-ext/Tests/Functional/AmqpCommonUseCasesTest.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pkg/amqp-ext/Tests/Functional/AmqpCommonUseCasesTest.php b/pkg/amqp-ext/Tests/Functional/AmqpCommonUseCasesTest.php index a90b1d306..ee53ad90b 100644 --- a/pkg/amqp-ext/Tests/Functional/AmqpCommonUseCasesTest.php +++ b/pkg/amqp-ext/Tests/Functional/AmqpCommonUseCasesTest.php @@ -112,6 +112,7 @@ public function testProduceAndReceiveOneMessageSentDirectlyToTemporaryQueue() $queue = $this->amqpContext->createTemporaryQueue(); $message = $this->amqpContext->createMessage(__METHOD__); + $message->setDeliveryTag(145); $producer = $this->amqpContext->createProducer(); $producer->send($queue, $message); @@ -137,6 +138,7 @@ public function testProduceAndReceiveOneMessageSentDirectlyToTopic() $this->amqpContext->bind(new AmqpBind($topic, $queue)); $message = $this->amqpContext->createMessage(__METHOD__); + $message->setDeliveryTag(145); $producer = $this->amqpContext->createProducer(); $producer->send($topic, $message); @@ -158,10 +160,11 @@ public function testConsumerReceiveMessageFromTopicDirectly() $this->amqpContext->declareTopic($topic); $consumer = $this->amqpContext->createConsumer($topic); - //guard + // guard $this->assertNull($consumer->receive(1000)); $message = $this->amqpContext->createMessage(__METHOD__); + $message->setDeliveryTag(145); $producer = $this->amqpContext->createProducer(); $producer->send($topic, $message); @@ -181,10 +184,11 @@ public function testConsumerReceiveMessageWithZeroTimeout() $this->amqpContext->declareTopic($topic); $consumer = $this->amqpContext->createConsumer($topic); - //guard + // guard $this->assertNull($consumer->receive(1000)); $message = $this->amqpContext->createMessage(__METHOD__); + $message->setDeliveryTag(145); $producer = $this->amqpContext->createProducer(); $producer->send($topic, $message); @@ -205,6 +209,7 @@ public function testPurgeMessagesFromQueue() $consumer = $this->amqpContext->createConsumer($queue); $message = $this->amqpContext->createMessage(__METHOD__); + $message->setDeliveryTag(145); $producer = $this->amqpContext->createProducer(); $producer->send($queue, $message); From 21a36c9931d7222f89d0ce6f83d077186e9c713b Mon Sep 17 00:00:00 2001 From: philippe PICHET Date: Fri, 2 Aug 2024 11:21:00 +0200 Subject: [PATCH 05/17] Use new image of localstack to fixing error in SQS and SNS in CI --- docker-compose.yml | 18 +++++++++--------- docker/bin/test.sh | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index c5fa5545b..b6696e9c0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,7 +7,7 @@ services: build: context: docker args: - PHP_VERSION: "${PHP_VERSION:-7.4}" + PHP_VERSION: "${PHP_VERSION:-8.2}" depends_on: - rabbitmq - mysql @@ -38,16 +38,16 @@ services: - PREDIS_DSN=redis+predis://redis - PHPREDIS_DSN=redis+phpredis://redis - GPS_DSN=gps:?projectId=mqdev&emulatorHost=http://google-pubsub:8085 - - SQS_DSN=sqs:?key=key&secret=secret®ion=us-east-1&endpoint=http://localstack:4576&version=latest - - SNS_DSN=sns:?key=key&secret=secret®ion=us-east-1&endpoint=http://localstack:4575&version=latest - - SNSQS_DSN=snsqs:?key=key&secret=secret®ion=us-east-1&sns_endpoint=http://localstack:4575&sqs_endpoint=http://localstack:4576&version=latest + - SQS_DSN=sqs:?key=key&secret=secret®ion=us-east-1&endpoint=http://localstack:4566&version=latest + - SNS_DSN=sns:?key=key&secret=secret®ion=us-east-1&endpoint=http://localstack:4566&version=latest + - SNSQS_DSN=snsqs:?key=key&secret=secret®ion=us-east-1&sns_endpoint=http://localstack:4566&sqs_endpoint=http://localstack:4566&version=latest - WAMP_DSN=wamp://thruway:9090 - REDIS_HOST=redis - REDIS_PORT=6379 - AWS_SQS_KEY=key - AWS_SQS_SECRET=secret - AWS_SQS_REGION=us-east-1 - - AWS_SQS_ENDPOINT=http://localstack:4576 + - AWS_SQS_ENDPOINT=http://localstack:4566 - AWS_SQS_VERSION=latest - BEANSTALKD_DSN=beanstalk://beanstalkd:11300 - GEARMAN_DSN=gearman://gearmand:4730 @@ -127,13 +127,13 @@ services: - '9090:9090' localstack: - image: 'localstack/localstack:0.8.10' + image: 'localstack/localstack' ports: - - '4576:4576' - - '4575:4575' + - "127.0.0.1:4566:4566" # LocalStack Gateway + - "127.0.0.1:4510-4559:4510-4559" # external services port range environment: HOSTNAME_EXTERNAL: 'localstack' - SERVICES: 'sqs,sns' + SERVICES: 's3,sqs,sns' influxdb: image: 'influxdb:latest' diff --git a/docker/bin/test.sh b/docker/bin/test.sh index 2070584bb..cfc94aab5 100755 --- a/docker/bin/test.sh +++ b/docker/bin/test.sh @@ -39,7 +39,7 @@ waitForService gearmand 4730 50 waitForService kafka 9092 50 waitForService mongo 27017 50 waitForService thruway 9090 50 -waitForService localstack 4576 50 +waitForService localstack 4566 50 php docker/bin/refresh-mysql-database.php || exit 1 php docker/bin/refresh-postgres-database.php || exit 1 From 20fe023c764dd69832798f38572a2a9c697f3d4e Mon Sep 17 00:00:00 2001 From: philippe PICHET Date: Tue, 6 Aug 2024 14:29:51 +0200 Subject: [PATCH 06/17] revert docker php version --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index b6696e9c0..3198e285f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,7 +7,7 @@ services: build: context: docker args: - PHP_VERSION: "${PHP_VERSION:-8.2}" + PHP_VERSION: "${PHP_VERSION:-7.4}" depends_on: - rabbitmq - mysql From 45b7a63aa65ea2db03013259cbe157457cf09191 Mon Sep 17 00:00:00 2001 From: philippe PICHET Date: Tue, 6 Aug 2024 15:07:56 +0200 Subject: [PATCH 07/17] Replace docker compose V2 instead V1 --- bin/dev | 2 +- bin/test.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/dev b/bin/dev index a50b7ad66..b7434741b 100755 --- a/bin/dev +++ b/bin/dev @@ -6,7 +6,7 @@ set -e while getopts "bustefdp" OPTION; do case $OPTION in b) - docker-compose pull -q && docker-compose build + docker compose pull -q && docker compose build ;; u) docker-compose up diff --git a/bin/test.sh b/bin/test.sh index f392e616b..5cb858ad6 100755 --- a/bin/test.sh +++ b/bin/test.sh @@ -3,4 +3,4 @@ set -x set -e -docker-compose run --workdir="/mqdev" --rm dev ./docker/bin/test.sh $@ +docker compose run --workdir="/mqdev" --rm dev ./docker/bin/test.sh $@ From cdfd18eb980bdccaf7e37e2854ff6bdd31d2e761 Mon Sep 17 00:00:00 2001 From: philippe PICHET Date: Wed, 7 Aug 2024 10:51:35 +0200 Subject: [PATCH 08/17] Remove all docker-composer and use docker compose --- bin/changelog | 4 ++-- bin/dev | 6 +++--- docs/contribution.md | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/bin/changelog b/bin/changelog index 8a9296175..b2dff8b4f 100755 --- a/bin/changelog +++ b/bin/changelog @@ -8,6 +8,6 @@ then exit 1 fi -docker-compose run -e CHANGELOG_GITHUB_TOKEN=${CHANGELOG_GITHUB_TOKEN:-""} --workdir="/mqdev" --rm generate-changelog github_changelog_generator --future-release "$1" --no-issues --unreleased-only --output "CHANGELOG_FUTURE.md" +docker compose run -e CHANGELOG_GITHUB_TOKEN=${CHANGELOG_GITHUB_TOKEN:-""} --workdir="/mqdev" --rm generate-changelog github_changelog_generator --future-release "$1" --no-issues --unreleased-only --output "CHANGELOG_FUTURE.md" -#git add CHANGELOG.md && git commit -m "Release $1" -S && git push origin "$CURRENT_BRANCH" \ No newline at end of file +#git add CHANGELOG.md && git commit -m "Release $1" -S && git push origin "$CURRENT_BRANCH" diff --git a/bin/dev b/bin/dev index b7434741b..45a3e7124 100755 --- a/bin/dev +++ b/bin/dev @@ -9,10 +9,10 @@ while getopts "bustefdp" OPTION; do docker compose pull -q && docker compose build ;; u) - docker-compose up + docker compose up ;; s) - docker-compose stop + docker compose stop ;; e) docker exec -it mqdev_dev_1 /bin/bash @@ -21,7 +21,7 @@ while getopts "bustefdp" OPTION; do ./bin/php-cs-fixer fix ;; - d) docker-compose run --workdir="/mqdev" --rm dev php pkg/enqueue-bundle/Tests/Functional/app/console.php config:dump-reference enqueue -vvv + d) docker compose run --workdir="/mqdev" --rm dev php pkg/enqueue-bundle/Tests/Functional/app/console.php config:dump-reference enqueue -vvv ;; \?) echo "Invalid option: -$OPTARG" >&2 diff --git a/docs/contribution.md b/docs/contribution.md index 455f6950e..68d051fc5 100644 --- a/docs/contribution.md +++ b/docs/contribution.md @@ -49,6 +49,6 @@ Once everything is done open a pull request on official repository. ## WTF?! -* If you get `rabbitmqssl: forward host lookup failed: Unknown host, wait for service rabbitmqssl:5671` do `docker-compose down`. +* If you get `rabbitmqssl: forward host lookup failed: Unknown host, wait for service rabbitmqssl:5671` do `docker compose down`. [back to index](index.md) From a1831b7b31a8da8ce46a370175b47a9f19606c7a Mon Sep 17 00:00:00 2001 From: philippe PICHET Date: Thu, 8 Aug 2024 10:52:57 +0200 Subject: [PATCH 09/17] try a composer update --- composer.json | 3 +-- pkg/sns/composer.json | 2 +- pkg/sqs/composer.json | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 5c0108e27..437fee594 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,7 @@ "doctrine/persistence": "^2.0|^3.0", "mongodb/mongodb": "^1.2", "pda/pheanstalk": "^3.1", - "aws/aws-sdk-php": "^3.155", + "aws/aws-sdk-php": "^3.319", "stomp-php/stomp-php": "^4.5|^5", "php-http/guzzle7-adapter": "^0.1.1", "php-http/client-common": "^2.2.1", @@ -137,4 +137,3 @@ } } } - diff --git a/pkg/sns/composer.json b/pkg/sns/composer.json index 297fac858..0a074ea28 100644 --- a/pkg/sns/composer.json +++ b/pkg/sns/composer.json @@ -9,7 +9,7 @@ "php": "^7.4|^8.0", "queue-interop/queue-interop": "^0.8", "enqueue/dsn": "^0.10", - "aws/aws-sdk-php": "~3.155" + "aws/aws-sdk-php": "~3.319" }, "require-dev": { "phpunit/phpunit": "^9.5", diff --git a/pkg/sqs/composer.json b/pkg/sqs/composer.json index d48b89015..fe4793da1 100644 --- a/pkg/sqs/composer.json +++ b/pkg/sqs/composer.json @@ -9,7 +9,7 @@ "php": "^7.4|^8.0", "queue-interop/queue-interop": "^0.8", "enqueue/dsn": "^0.10", - "aws/aws-sdk-php": "~3.155" + "aws/aws-sdk-php": "~3.319" }, "require-dev": { "phpunit/phpunit": "^9.5", From 50c6b12745f0a60d8db5a4a8fcfce7c69cb21413 Mon Sep 17 00:00:00 2001 From: philippe PICHET Date: Thu, 8 Aug 2024 17:14:47 +0200 Subject: [PATCH 10/17] try fix --- .../SnsQsSendToTopicAndReceiveNoWaitFromQueueTest.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pkg/snsqs/Tests/Spec/SnsQsSendToTopicAndReceiveNoWaitFromQueueTest.php b/pkg/snsqs/Tests/Spec/SnsQsSendToTopicAndReceiveNoWaitFromQueueTest.php index e370c1f32..a5fc7f72f 100644 --- a/pkg/snsqs/Tests/Spec/SnsQsSendToTopicAndReceiveNoWaitFromQueueTest.php +++ b/pkg/snsqs/Tests/Spec/SnsQsSendToTopicAndReceiveNoWaitFromQueueTest.php @@ -8,6 +8,7 @@ /** * @group functional + * * @retry 5 */ class SnsQsSendToTopicAndReceiveNoWaitFromQueueTest extends SendToTopicAndReceiveNoWaitFromQueueSpec @@ -15,6 +16,14 @@ class SnsQsSendToTopicAndReceiveNoWaitFromQueueTest extends SendToTopicAndReceiv use RetryTrait; use SnsQsFactoryTrait; + protected function setUp(): void + { + try { + $this->cleanUpSnsQs(); + } catch (\Exception $e) { + } + } + protected function tearDown(): void { parent::tearDown(); From 850f6a916374472f0dcc569705ac1ab4c4b695cb Mon Sep 17 00:00:00 2001 From: philippe PICHET Date: Fri, 9 Aug 2024 15:58:14 +0200 Subject: [PATCH 11/17] move the snsqs tests at the end --- phpunit.xml.dist | 8 ++++---- .../SnsQsSendToTopicAndReceiveNoWaitFromQueueTest.php | 8 -------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 1cd38e68b..f5ba01d8f 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -68,10 +68,6 @@ pkg/sns/Tests - - pkg/snsqs/Tests - - pkg/pheanstalk/Tests @@ -123,6 +119,10 @@ pkg/monitoring/Tests + + + pkg/snsqs/Tests + diff --git a/pkg/snsqs/Tests/Spec/SnsQsSendToTopicAndReceiveNoWaitFromQueueTest.php b/pkg/snsqs/Tests/Spec/SnsQsSendToTopicAndReceiveNoWaitFromQueueTest.php index a5fc7f72f..433fcf3a7 100644 --- a/pkg/snsqs/Tests/Spec/SnsQsSendToTopicAndReceiveNoWaitFromQueueTest.php +++ b/pkg/snsqs/Tests/Spec/SnsQsSendToTopicAndReceiveNoWaitFromQueueTest.php @@ -16,14 +16,6 @@ class SnsQsSendToTopicAndReceiveNoWaitFromQueueTest extends SendToTopicAndReceiv use RetryTrait; use SnsQsFactoryTrait; - protected function setUp(): void - { - try { - $this->cleanUpSnsQs(); - } catch (\Exception $e) { - } - } - protected function tearDown(): void { parent::tearDown(); From d748405a0ae94b41880b4ba4da143e04385ca732 Mon Sep 17 00:00:00 2001 From: philippe PICHET Date: Mon, 12 Aug 2024 09:32:16 +0200 Subject: [PATCH 12/17] use lower version of aws sdk php --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 437fee594..e17ab6570 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,7 @@ "doctrine/persistence": "^2.0|^3.0", "mongodb/mongodb": "^1.2", "pda/pheanstalk": "^3.1", - "aws/aws-sdk-php": "^3.319", + "aws/aws-sdk-php": "^3.290", "stomp-php/stomp-php": "^4.5|^5", "php-http/guzzle7-adapter": "^0.1.1", "php-http/client-common": "^2.2.1", From 10dea2a14d54d85dd5408d3a34d632ec0cd8b8e9 Mon Sep 17 00:00:00 2001 From: philippe PICHET Date: Mon, 12 Aug 2024 10:28:46 +0200 Subject: [PATCH 13/17] Use a property attributes instead of a key in headers --- docs/transport/gps.md | 15 --------------- pkg/gps/GpsMessage.php | 20 ++++++++++++-------- pkg/gps/Tests/GpsMessageTest.php | 2 +- pkg/gps/Tests/GpsProducerTest.php | 5 ++--- 4 files changed, 15 insertions(+), 27 deletions(-) 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 From 9aed45578a3ff99ae1982d84934c3c89ce06bb94 Mon Sep 17 00:00:00 2001 From: philippe PICHET Date: Mon, 12 Aug 2024 11:19:35 +0200 Subject: [PATCH 14/17] Update the composer of sqs and sns --- pkg/sns/composer.json | 2 +- pkg/sqs/composer.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/sns/composer.json b/pkg/sns/composer.json index 0a074ea28..3bf50bdaf 100644 --- a/pkg/sns/composer.json +++ b/pkg/sns/composer.json @@ -9,7 +9,7 @@ "php": "^7.4|^8.0", "queue-interop/queue-interop": "^0.8", "enqueue/dsn": "^0.10", - "aws/aws-sdk-php": "~3.319" + "aws/aws-sdk-php": "^3.290" }, "require-dev": { "phpunit/phpunit": "^9.5", diff --git a/pkg/sqs/composer.json b/pkg/sqs/composer.json index fe4793da1..cd50faf29 100644 --- a/pkg/sqs/composer.json +++ b/pkg/sqs/composer.json @@ -9,7 +9,7 @@ "php": "^7.4|^8.0", "queue-interop/queue-interop": "^0.8", "enqueue/dsn": "^0.10", - "aws/aws-sdk-php": "~3.319" + "aws/aws-sdk-php": "^3.290" }, "require-dev": { "phpunit/phpunit": "^9.5", From e2fae176f5d1724f005b3e40771117c70070d303 Mon Sep 17 00:00:00 2001 From: philippe PICHET Date: Mon, 12 Aug 2024 11:50:14 +0200 Subject: [PATCH 15/17] unserialize the attributes --- pkg/gps/GpsMessage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/gps/GpsMessage.php b/pkg/gps/GpsMessage.php index 4fff14859..1686ec937 100644 --- a/pkg/gps/GpsMessage.php +++ b/pkg/gps/GpsMessage.php @@ -167,7 +167,7 @@ public static function jsonUnserialize(string $json): self throw new \InvalidArgumentException(sprintf('The malformed json given. Error %s and message %s', json_last_error(), json_last_error_msg())); } - return new self($data['body'] ?? $json, $data['properties'] ?? [], $data['headers'] ?? []); + return new self($data['body'] ?? $json, $data['properties'] ?? [], $data['headers'] ?? [], $data['attributes'] ?? []); } public function getNativeMessage(): ?GoogleMessage From 719e9e8ace7a8b6d90ad340a2fd1540314665469 Mon Sep 17 00:00:00 2001 From: philippe PICHET Date: Mon, 12 Aug 2024 13:55:42 +0200 Subject: [PATCH 16/17] get attributes in unserialization --- pkg/gps/GpsMessage.php | 1 + pkg/gps/Tests/GpsMessageTest.php | 10 ++++++---- pkg/gps/Tests/GpsProducerTest.php | 4 ++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/pkg/gps/GpsMessage.php b/pkg/gps/GpsMessage.php index 1686ec937..684a7ba7b 100644 --- a/pkg/gps/GpsMessage.php +++ b/pkg/gps/GpsMessage.php @@ -157,6 +157,7 @@ public function jsonSerialize(): array 'body' => $this->getBody(), 'properties' => $this->getProperties(), 'headers' => $this->getHeaders(), + 'attributes' => $this->getAttributes(), ]; } diff --git a/pkg/gps/Tests/GpsMessageTest.php b/pkg/gps/Tests/GpsMessageTest.php index 5b48ca0ca..ee9e652cd 100644 --- a/pkg/gps/Tests/GpsMessageTest.php +++ b/pkg/gps/Tests/GpsMessageTest.php @@ -18,14 +18,14 @@ public function testCouldSetGetNativeMessage() public function testColdBeSerializedToJson() { - $message = new GpsMessage('theBody', ['thePropFoo' => 'thePropFooVal'], ['theHeaderFoo' => 'theHeaderFooVal']); + $message = new GpsMessage('theBody', ['thePropFoo' => 'thePropFooVal'], ['theHeaderFoo' => 'theHeaderFooVal'], ['theAttributeFoo' => 'theAttributeFooVal']); - $this->assertEquals('{"body":"theBody","properties":{"thePropFoo":"thePropFooVal"},"headers":{"theHeaderFoo":"theHeaderFooVal"}}', json_encode($message)); + $this->assertEquals('{"body":"theBody","properties":{"thePropFoo":"thePropFooVal"},"headers":{"theHeaderFoo":"theHeaderFooVal"},"attributes":{"theAttributeFoo":"theAttributeFooVal"}}', json_encode($message)); } public function testCouldBeUnserializedFromJson() { - $message = new GpsMessage('theBody', ['thePropFoo' => 'thePropFooVal'], ['theHeaderFoo' => 'theHeaderFooVal']); + $message = new GpsMessage('theBody', ['thePropFoo' => 'thePropFooVal'], ['theHeaderFoo' => 'theHeaderFooVal'], ['theAttributeFoo' => 'theAttributeFooVal']); $json = json_encode($message); @@ -40,7 +40,7 @@ public function testCouldBeUnserializedFromJson() public function testMessageEntityCouldBeUnserializedFromJson() { - $json = '{"body":"theBody","properties":{"thePropFoo":"thePropFooVal"},"headers":{"theHeaderFoo":"theHeaderFooVal"}}'; + $json = '{"body":"theBody","properties":{"thePropFoo":"thePropFooVal"},"headers":{"theHeaderFoo":"theHeaderFooVal"},"attributes":{"theAttributeFoo":"theAttributeFooVal"}}'; $unserializedMessage = GpsMessage::jsonUnserialize($json); @@ -49,6 +49,7 @@ public function testMessageEntityCouldBeUnserializedFromJson() $this->assertEquals($decoded['body'], $unserializedMessage->getBody()); $this->assertEquals($decoded['properties'], $unserializedMessage->getProperties()); $this->assertEquals($decoded['headers'], $unserializedMessage->getHeaders()); + $this->assertEquals($decoded['attributes'], $unserializedMessage->getAttributes()); } public function testMessagePayloadCouldBeUnserializedFromJson() @@ -61,6 +62,7 @@ public function testMessagePayloadCouldBeUnserializedFromJson() $this->assertEquals($json, $unserializedMessage->getBody()); $this->assertEquals([], $unserializedMessage->getProperties()); $this->assertEquals([], $unserializedMessage->getHeaders()); + $this->assertEquals([], $unserializedMessage->getAttributes()); } public function testThrowIfMalformedJsonGivenOnUnsterilizedFromJson() diff --git a/pkg/gps/Tests/GpsProducerTest.php b/pkg/gps/Tests/GpsProducerTest.php index c7de83e44..34dc2504f 100644 --- a/pkg/gps/Tests/GpsProducerTest.php +++ b/pkg/gps/Tests/GpsProducerTest.php @@ -34,7 +34,7 @@ public function testShouldSendMessage() ->expects($this->once()) ->method('publish') ->with($this->identicalTo([ - 'data' => '{"body":"","properties":[],"headers":[]}', + 'data' => '{"body":"","properties":[],"headers":[],"attributes":[]}', ])); $client = $this->createPubSubClientMock(); @@ -65,7 +65,7 @@ public function testShouldSendMessageWithAttributes() $gtopic ->expects($this->once()) ->method('publish') - ->with($this->identicalTo(['data' => '{"body":"","properties":[],"headers":[]}', 'attributes' => ['key1' => 'value1']])) + ->with($this->identicalTo(['data' => '{"body":"","properties":[],"headers":[],"attributes":{"key1":"value1"}}', 'attributes' => ['key1' => 'value1']])) ; $client = $this->createPubSubClientMock(); From cf6bbec9f1aa225e6000014adc86b42b5aec455f Mon Sep 17 00:00:00 2001 From: philippe PICHET Date: Mon, 12 Aug 2024 14:12:18 +0200 Subject: [PATCH 17/17] uncomment on chagelog and set a version of localstack image --- bin/changelog | 2 +- docker-compose.yml | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/bin/changelog b/bin/changelog index b2dff8b4f..ba2db0813 100755 --- a/bin/changelog +++ b/bin/changelog @@ -10,4 +10,4 @@ fi docker compose run -e CHANGELOG_GITHUB_TOKEN=${CHANGELOG_GITHUB_TOKEN:-""} --workdir="/mqdev" --rm generate-changelog github_changelog_generator --future-release "$1" --no-issues --unreleased-only --output "CHANGELOG_FUTURE.md" -#git add CHANGELOG.md && git commit -m "Release $1" -S && git push origin "$CURRENT_BRANCH" + git add CHANGELOG.md && git commit -m "Release $1" -S && git push origin "$CURRENT_BRANCH" diff --git a/docker-compose.yml b/docker-compose.yml index 3198e285f..a5b884b31 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -83,6 +83,7 @@ services: mysql: image: mysql:5.7 + platform: linux/amd64 environment: MYSQL_ROOT_PASSWORD: rootpass MYSQL_DATABASE: mqdev @@ -127,7 +128,7 @@ services: - '9090:9090' localstack: - image: 'localstack/localstack' + image: 'localstack/localstack:3.6.0' ports: - "127.0.0.1:4566:4566" # LocalStack Gateway - "127.0.0.1:4510-4559:4510-4559" # external services port range