mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
fix(sns): make Subscribe idempotent for same topic+protocol+endpoint (#185)
AWS Subscribe returns the existing subscription when called with the same TopicArn, Protocol, and Endpoint. Floci was always creating a new subscription, causing duplicates to accumulate across test re-runs.
This commit is contained in:
1 parent
fe4ffd1ee4
commit
858775c38e
3 files changed
+50
No files matched your search
@@ -31,6 +31,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@@ -186,6 +187,14 @@ public class SnsService {
|
||||
if (protocol == null || protocol.isBlank()) {
|
||||
throw new AwsException("InvalidParameter", "Protocol is required.", 400);
|
||||
}
|
||||
|
||||
for (Subscription existing : subscriptionsByTopic(topicArn, region)) {
|
||||
if (protocol.equals(existing.getProtocol())
|
||||
&& Objects.equals(endpoint, existing.getEndpoint())) {
|
||||
return existing;
|
||||
}
|
||||
}
|
||||
|
||||
String subscriptionArn = topicArn + ":" + UUID.randomUUID().toString();
|
||||
Subscription subscription = new Subscription(subscriptionArn, topicArn, protocol, endpoint,
|
||||
regionResolver.getAccountId());
|
||||
|
||||
Reference in new issue
Block a user