8000 Apply fixes proposed in CR · symfony/symfony@ff9a8ee · GitHub
[go: up one dir, main page]

Skip to content

Commit ff9a8ee

Browse files
committed
Apply fixes proposed in CR
1 parent dc34525 commit ff9a8ee

File tree

4 files changed

+23
-13
lines changed

4 files changed

+23
-13
lines changed

src/Symfony/Component/Messenger/Bridge/AmazonSqs/Tests/Transport/AmazonSqsSenderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function testSendWithAmazonSqsFifoStamp(): void
4949
->disableOriginalConstructor()
5050
->getMock();
5151
$connection->expects($this->once())->method('send')
52-
->with($encoded['body'], $encoded['headers'], $stamp->getAttributes());
52+
->with($encoded['body'], $encoded['headers'], 0, $stamp->getMessageGroupId(), $stamp->getMessageDeduplicationId());
5353

5454
$serializer = $this->getMockBuilder(SerializerInterface::class)->getMock();
5555
$serializer->method('encode')->with($envelope)->willReturnOnConsecutiveCalls($encoded);

src/Symfony/Component/Messenger/Bridge/AmazonSqs/Transport/AmazonSqsFifoStamp.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,19 @@ final class AmazonSqsFifoStamp implements NonSendableStampInterface
1919

2020
private $messageDeduplicationId;
2121

22-
public function __construct(string $messageGroupId, string $messageDeduplicationId)
22+
public function __construct(?string $messageGroupId = null, ?string $messageDeduplicationId = null)
2323
{
2424
$this->messageGroupId = $messageGroupId;
2525
$this->messageDeduplicationId = $messageDeduplicationId;
2626
}
2727

28-
public function getAttributes(): array
28+
public function getMessageGroupId(): ?string
2929
{
30-
return [
31-
'messageGroupId' => $this->messageGroupId,
32-
'messageDeduplicationId' => $this->messageDeduplicationId,
33-
];
30+
return $this->messageGroupId;
31+
}
32+
33+
public function getMessageDeduplicationId(): ?string
34+
{
35+
return $this->messageDeduplicationId;
3436
}
3537
}

src/Symfony/Component/Messenger/Bridge/AmazonSqs/Transport/AmazonSqsSender.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,24 @@ public function send(Envelope $envelope): Envelope
4343
$delayStamp = $envelope->last(DelayStamp::class);
4444
$delay = null !== $delayStamp ? (int) ceil($delayStamp->getDelay() / 1000) : 0;
4545

46-
$attributes = [];
46+
$messageGroupId = null;
47+
$messageDeduplicationId = null;
4748

4849
/** @var AmazonSqsFifoStamp|null $amazonSqsFifoStamp */
4950
$amazonSqsFifoStamp = $envelope->last(AmazonSqsFifoStamp::class);
5051
if (null !== $amazonSqsFifoStamp) {
51-
$attributes = $amazonSqsFifoStamp->getAttributes();
52+
$messageGroupId = $amazonSqsFifoStamp->getMessageGroupId();
53+
$messageDeduplicationId = $amazonSqsFifoStamp->getMessageDeduplicationId();
5254
}
5355

5456
try {
55-
$this->connection->send($encodedMessage['body'], $encodedMessage['headers'] ?? [], $attributes, $delay);
57+
$this->connection->send(
58+
$encodedMessage['body'],
59+
$encodedMessage['headers'] ?? [],
60+
$delay,
61+
$messageGroupId,
62+
< 8000 span class=pl-s1>$messageDeduplicationId
63+
);
5664
} catch (HttpExceptionInterface $e) {
5765
throw new TransportException($e->getMessage(), 0, $e);
5866
}

src/Symfony/Component/Messenger/Bridge/AmazonSqs/Transport/Connection.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ public function getMessageCount(): int
240240
return 0;
241241
}
242242

243-
public function send(string $body, array $headers, array $attributes, int $delay = 0): void
243+
public function send(string $body, array $headers, int $delay = 0, ?string $messageGroupId = null, ?string $messageDeduplicationId = null): void
244244
{
245245
if ($this->configuration['auto_setup']) {
246246
$this->setup();
@@ -255,8 +255,8 @@ public function send(string $body, array $headers, array $attributes, int $delay
255255
];
256256

257257
if ($this->isFifoQueue($this->configuration['queue_name'])) {
258-
$parameters['MessageGroupId'] = $attributes['messageGroupId'] ?? __METHOD__;
259-
$parameters['MessageDeduplicationId'] = $attributes['messageDeduplicationId'] ?? sha1($messageBody);
258+
$parameters['MessageGroupId'] = null !== $messageGroupId ? $messageGroupId : __METHOD__;
259+
$parameters['MessageDeduplicationId'] = null !== $messageDeduplicationId ? $messageDeduplicationId : sha1($messageBody);
260260
}
261261

262262
$this->call($this->getQueueUrl(), $parameters);

0 commit comments

Comments
 (0)
0