Skip to content

Commit 5b8c771

Browse files
author
Kate Simozhenko
committed
add FIFO logic to SNS
1 parent bb4a036 commit 5b8c771

File tree

3 files changed

+92
-0
lines changed

3 files changed

+92
-0
lines changed

Diff for: pkg/sns/SnsDestination.php

+30
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,36 @@ public function getDeliveryPolicy(): ?int
7070
return $this->getAttribute('DeliveryPolicy');
7171
}
7272

73+
/**
74+
* Only FIFO.
75+
*
76+
* Designates a topic as FIFO. You can provide this attribute only during queue creation.
77+
* You can't change it for an existing topic. When you set this attribute, you must provide aMessageGroupId
78+
* explicitly.
79+
* For more information, see https://docs.aws.amazon.com/sns/latest/dg/sns-fifo-topics.html
80+
*
81+
* @param bool $enable
82+
*/
83+
public function setFifoTopic(bool $enable): void
84+
{
85+
$value = $enable ? 'true' : null;
86+
87+
$this->setAttribute('FifoTopic', $value);
88+
}
89+
90+
/**
91+
* Only FIFO.
92+
*
93+
* Enables content-based deduplication.
94+
* For more information, see: https://docs.aws.amazon.com/sns/latest/dg/fifo-message-dedup.html
95+
*/
96+
public function setContentBasedDeduplication(bool $enable): void
97+
{
98+
$value = $enable ? 'true' : null;
99+
100+
$this->setAttribute('ContentBasedDeduplication', $value);
101+
}
102+
73103
public function getAttributes(): array
74104
{
75105
return $this->attributes;

Diff for: pkg/sns/SnsMessage.php

+54
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@ class SnsMessage implements Message
4242
*/
4343
private $targetArn;
4444

45+
/**
46+
* @var string|null
47+
*/
48+
private $messageGroupId;
49+
50+
/**
51+
* @var string|null
52+
*/
53+
private $messageDeduplicationId;
54+
4555
/**
4656
* SnsMessage constructor.
4757
*
@@ -220,4 +230,48 @@ public function setTargetArn(?string $targetArn): void
220230
{
221231
$this->targetArn = $targetArn;
222232
}
233+
234+
/**
235+
* Only FIFO.
236+
*
237+
* The tag that specifies that a message belongs to a specific message group. Messages that belong to the same
238+
* message group are processed in a FIFO manner (however, messages in different message groups might be processed
239+
* out of order).
240+
* To interleave multiple ordered streams within a single queue, use MessageGroupId values (for example, session
241+
* data for multiple users). In this scenario, multiple readers can process the queue, but the session data
242+
* of each user is processed in a FIFO fashion.
243+
* For more information, see: https://docs.aws.amazon.com/sns/latest/dg/fifo-message-grouping.html
244+
*
245+
* @param string|null $id
246+
*/
247+
public function setMessageGroupId(string $id = null): void
248+
{
249+
$this->messageGroupId = $id;
250+
}
251+
252+
/**
253+
* @return string|null
254+
*/
255+
public function getMessageGroupId(): ?string
256+
{
257+
return $this->messageGroupId;
258+
}
259+
260+
/**
261+
* Only FIFO.
262+
*
263+
* The token used for deduplication of sent messages. If a message with a particular MessageDeduplicationId is
264+
* sent successfully, any messages sent with the same MessageDeduplicationId are accepted successfully but
265+
* aren't delivered during the 5-minute deduplication interval.
266+
* For more information, see https://docs.aws.amazon.com/sns/latest/dg/fifo-message-dedup.html
267+
*/
268+
public function setMessageDeduplicationId(string $id = null): void
269+
{
270+
$this->messageDeduplicationId = $id;
271+
}
272+
273+
public function getMessageDeduplicationId(): ?string
274+
{
275+
return $this->messageDeduplicationId;
276+
}
223277
}

Diff for: pkg/sns/SnsProducer.php

+8
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ public function send(Destination $destination, Message $message): void
7777
$arguments['TargetArn'] = $targetArn;
7878
}
7979

80+
if ($messageGroupId = $message->getMessageGroupId()) {
81+
$arguments['MessageGroupId'] = $messageGroupId;
82+
}
83+
84+
if ($messageDeduplicationId = $message->getMessageDeduplicationId()) {
85+
$arguments['MessageDeduplicationId'] = $messageDeduplicationId;
86+
}
87+
8088
$result = $this->context->getSnsClient()->publish($arguments);
8189

8290
if (false == $result->hasKey('MessageId')) {

0 commit comments

Comments
 (0)