Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc424da4

Browse files
tyxnicolas-grekas
authored andcommitted
[Messenger] [Sqs] AddAddFifoStamp middleware
1 parent1a72bd5 commitc424da4

File tree

5 files changed

+207
-0
lines changed

5 files changed

+207
-0
lines changed

‎src/Symfony/Component/Messenger/Bridge/AmazonSqs/CHANGELOG.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
6.4
5+
---
6+
7+
* Add`AddFifoStampMiddleware` to help adding`AmazonSqsFifoStamp`
8+
49
6.1
510
---
611

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Component\Messenger\Bridge\AmazonSqs;
13+
14+
/**
15+
* @see https://docs.aws.amazon.com/en_gb/AWSSimpleQueueService/latest/SQSDeveloperGuide/using-messagededuplicationid-property.html
16+
*/
17+
interface MessageDeduplicationAwareInterface
18+
{
19+
/**
20+
* The max length of MessageDeduplicationId is 128 characters.
21+
* Valid values: alphanumeric characters and punctuation (!"#$%&'()*+,-./:;<=>?@[]^_`{|}~).
22+
*/
23+
publicfunctiongetMessageDeduplicationId(): ?string;
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Component\Messenger\Bridge\AmazonSqs;
13+
14+
/**
15+
* @see https://docs.aws.amazon.com/en_gb/AWSSimpleQueueService/latest/SQSDeveloperGuide/using-messagegroupid-property.html
16+
*/
17+
interface MessageGroupAwareInterface
18+
{
19+
/**
20+
* The max length of MessageGroupId is 128 characters.
21+
* Valid values: alphanumeric characters and punctuation (!"#$%&'()*+,-./:;<=>?@[]^_`{|}~).
22+
*/
23+
publicfunctiongetMessageGroupId(): ?string;
24+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Component\Messenger\Bridge\AmazonSqs\Middleware;
13+
14+
useSymfony\Component\Messenger\Bridge\AmazonSqs\MessageDeduplicationAwareInterface;
15+
useSymfony\Component\Messenger\Bridge\AmazonSqs\MessageGroupAwareInterface;
16+
useSymfony\Component\Messenger\Bridge\AmazonSqs\Transport\AmazonSqsFifoStamp;
17+
useSymfony\Component\Messenger\Envelope;
18+
useSymfony\Component\Messenger\Middleware\MiddlewareInterface;
19+
useSymfony\Component\Messenger\Middleware\StackInterface;
20+
21+
finalclass AddFifoStampMiddlewareimplements MiddlewareInterface
22+
{
23+
publicfunctionhandle(Envelope$envelope,StackInterface$stack):Envelope
24+
{
25+
$message =$envelope->getMessage();
26+
$messageGroupId =null;
27+
$messageDeduplicationId =null;
28+
29+
if ($messageinstanceof MessageGroupAwareInterface) {
30+
$messageGroupId =$message->getMessageGroupId();
31+
}
32+
if ($messageinstanceof MessageDeduplicationAwareInterface) {
33+
$messageDeduplicationId =$message->getMessageDeduplicationId();
34+
}
35+
36+
if (null !==$messageGroupId ||null !==$messageDeduplicationId) {
37+
$envelope =$envelope->with(newAmazonSqsFifoStamp($messageGroupId,$messageDeduplicationId));
38+
}
39+
40+
return$stack->next()->handle($envelope,$stack);
41+
}
42+
}
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Component\Messenger\Bridge\AmazonSqs\Tests\Middleware;
13+
14+
useSymfony\Component\Messenger\Bridge\AmazonSqs\MessageDeduplicationAwareInterface;
15+
useSymfony\Component\Messenger\Bridge\AmazonSqs\MessageGroupAwareInterface;
16+
useSymfony\Component\Messenger\Bridge\AmazonSqs\Middleware\AddFifoStampMiddleware;
17+
useSymfony\Component\Messenger\Bridge\AmazonSqs\Transport\AmazonSqsFifoStamp;
18+
useSymfony\Component\Messenger\Envelope;
19+
useSymfony\Component\Messenger\Test\Middleware\MiddlewareTestCase;
20+
21+
class AddFifoStampTestextends MiddlewareTestCase
22+
{
23+
publicfunctiontestAddStampWithGroupIdOnly()
24+
{
25+
$middleware =newAddFifoStampMiddleware();
26+
$envelope =newEnvelope(newWithMessageGroupIdMessage('groupId'));
27+
$finalEnvelope =$middleware->handle($envelope,$this->getStackMock());
28+
$stamp =$finalEnvelope->last(AmazonSqsFifoStamp::class);
29+
$this->assertInstanceOf(AmazonSqsFifoStamp::class,$stamp);
30+
$this->assertSame('groupId',$stamp->getMessageGroupId());
31+
$this->assertNull($stamp->getMessageDeduplicationId());
32+
}
33+
34+
publicfunctiontestHandleWithDeduplicationIdOnly()
35+
{
36+
$middleware =newAddFifoStampMiddleware();
37+
$envelope =newEnvelope(newWithMessageDeduplicationIdMessage('deduplicationId'));
38+
$finalEnvelope =$middleware->handle($envelope,$this->getStackMock());
39+
$stamp =$finalEnvelope->last(AmazonSqsFifoStamp::class);
40+
$this->assertInstanceOf(AmazonSqsFifoStamp::class,$stamp);
41+
$this->assertSame('deduplicationId',$stamp->getMessageDeduplicationId());
42+
$this->assertNull($stamp->getMessageGroupId());
43+
}
44+
45+
publicfunctiontestHandleWithGroupIdAndDeduplicationId()
46+
{
47+
$middleware =newAddFifoStampMiddleware();
48+
$envelope =newEnvelope(newWithMessageDeduplicationIdAndMessageGroupIdMessage('my_group','my_random_id'));
49+
$finalEnvelope =$middleware->handle($envelope,$this->getStackMock());
50+
$stamp =$finalEnvelope->last(AmazonSqsFifoStamp::class);
51+
$this->assertInstanceOf(AmazonSqsFifoStamp::class,$stamp);
52+
$this->assertSame('my_random_id',$stamp->getMessageDeduplicationId());
53+
$this->assertSame('my_group',$stamp->getMessageGroupId());
54+
}
55+
56+
publicfunctiontestHandleWithoutId()
57+
{
58+
$middleware =newAddFifoStampMiddleware();
59+
$envelope =newEnvelope(newWithoutIdMessage());
60+
$finalEnvelope =$middleware->handle($envelope,$this->getStackMock());
61+
$stamp =$finalEnvelope->last(AmazonSqsFifoStamp::class);
62+
$this->assertNull($stamp);
63+
}
64+
}
65+
66+
class WithMessageDeduplicationIdAndMessageGroupIdMessageimplements MessageDeduplicationAwareInterface, MessageGroupAwareInterface
67+
{
68+
publicfunction__construct(
69+
privatestring$messageGroupId,
70+
privatestring$messageDeduplicationId,
71+
) {
72+
}
73+
74+
publicfunctiongetMessageDeduplicationId(): ?string
75+
{
76+
return$this->messageDeduplicationId;
77+
}
78+
79+
publicfunctiongetMessageGroupId(): ?string
80+
{
81+
return$this->messageGroupId;
82+
}
83+
}
84+
85+
class WithMessageDeduplicationIdMessageimplements MessageDeduplicationAwareInterface
86+
{
87+
publicfunction__construct(
88+
privatestring$messageDeduplicationId,
89+
) {
90+
}
91+
92+
publicfunctiongetMessageDeduplicationId(): ?string
93+
{
94+
return$this->messageDeduplicationId;
95+
}
96+
}
97+
98+
class WithMessageGroupIdMessageimplements MessageGroupAwareInterface
99+
{
100+
publicfunction__construct(
101+
privatestring$messageGroupId,
102+
) {
103+
}
104+
105+
publicfunctiongetMessageGroupId(): ?string
106+
{
107+
return$this->messageGroupId;
108+
}
109+
}
110+
class WithoutIdMessage
111+
{
112+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp