-
Notifications
You must be signed in to change notification settings - Fork 259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GH-1294 Add support to FIFO #3437
Open
lillo42
wants to merge
21
commits into
BrighterCommand:master
Choose a base branch
from
lillo42:GH-1294.add.aws.fifo
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
1ddd758
GH-1294 Add support to FIFO
lillo42 582d57c
GH-1294 fixes build
lillo42 c9e3033
GH-1294 Add Fifo test
lillo42 7a188b5
Merge with master
lillo42 ab9d3e9
GH-1294 fixes unit test
lillo42 c9b7e83
GH-1294 Improve support to LocalStack
lillo42 c94003e
GH-1294 Use AwsFactory
lillo42 9226568
Merge branch 'master' into GH-1294.add.aws.fifo
lillo42 849d21f
Merge branch 'master' into GH-1294.add.aws.fifo
lillo42 c9b3f7c
Merge branch 'master' into GH-1294.add.aws.fifo
lillo42 85db988
GH-1294 Fixes the majority of test, improve support to localstack and…
lillo42 e449da8
GH-1294 Fixes http test
lillo42 527e14a
Add Fifo test
lillo42 0cfb765
Merge with master
lillo42 11ffdef
GH-1294 fixes DLQ, Get System Attribute & Unit tests
lillo42 75f431b
GH-1294 Improve Valid SQS/SNS name logic
lillo42 58a701e
GH-1294 Improve Valid SQS/SNS name logic
lillo42 4299f90
Add support to SQS Publication and add FIFO tests
lillo42 e849a3f
Fixes SQS unit tests
lillo42 5abb8d6
GH-1294 Add Fifo sample
lillo42 3f02f03
Improvements
lillo42 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
version: '3' | ||
|
||
services: | ||
localstack: | ||
image: localstack/localstack | ||
environment: | ||
# LocalStack configuration: https://docs.localstack.cloud/references/configuration/ | ||
- "SERVICES=s3,sqs,sns,dynamodb" | ||
ports: | ||
- "4566:4566" # LocalStack Gateway | ||
- "4510-4559:4510-4559" # External services port range | ||
volumes: | ||
- "/var/run/docker.sock:/var/run/docker.sock" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
#region Licence | ||
|
||
/* The MIT License (MIT) | ||
Copyright © 2022 Ian Cooper <[email protected]> | ||
|
||
|
@@ -25,6 +26,7 @@ THE SOFTWARE. */ | |
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Amazon.Runtime.Internal.Transform; | ||
using Amazon.SimpleNotificationService; | ||
using Amazon.SimpleNotificationService.Model; | ||
using Microsoft.Extensions.Logging; | ||
|
@@ -46,43 +48,73 @@ public AWSMessagingGateway(AWSMessagingGatewayConnection awsConnection) | |
_awsClientFactory = new AWSClientFactory(awsConnection); | ||
} | ||
|
||
protected async Task<string> EnsureTopicAsync(RoutingKey topic, SnsAttributes attributes, TopicFindBy topicFindBy, OnMissingChannel makeTopic) | ||
protected async Task<string> EnsureTopicAsync(RoutingKey topic, SnsAttributes attributes, | ||
TopicFindBy topicFindBy, OnMissingChannel makeTopic, SnsSqsType snsSqsType, bool deduplication) | ||
{ | ||
//on validate or assume, turn a routing key into a topicARN | ||
if ((makeTopic == OnMissingChannel.Assume) || (makeTopic == OnMissingChannel.Validate)) | ||
await ValidateTopicAsync(topic, topicFindBy, makeTopic); | ||
else if (makeTopic == OnMissingChannel.Create) CreateTopic(topic, attributes); | ||
if (makeTopic is OnMissingChannel.Assume or OnMissingChannel.Validate) | ||
{ | ||
await ValidateTopicAsync(topic, topicFindBy, makeTopic, snsSqsType); | ||
} | ||
else if (makeTopic == OnMissingChannel.Create) | ||
{ | ||
CreateTopic(topic, attributes, snsSqsType, deduplication); | ||
} | ||
return ChannelTopicArn; | ||
} | ||
|
||
private void CreateTopic(RoutingKey topicName, SnsAttributes snsAttributes) | ||
private void CreateTopic(RoutingKey topicName, | ||
SnsAttributes snsAttributes, | ||
SnsSqsType snsSqsType, | ||
bool deduplication) | ||
{ | ||
using var snsClient = _awsClientFactory.CreateSnsClient(); | ||
var attributes = new Dictionary<string, string>(); | ||
if (snsAttributes != null) | ||
{ | ||
if (!string.IsNullOrEmpty(snsAttributes.DeliveryPolicy)) attributes.Add("DeliveryPolicy", snsAttributes.DeliveryPolicy); | ||
if (!string.IsNullOrEmpty(snsAttributes.Policy)) attributes.Add("Policy", snsAttributes.Policy); | ||
if (!string.IsNullOrEmpty(snsAttributes.DeliveryPolicy)) | ||
{ | ||
attributes.Add("DeliveryPolicy", snsAttributes.DeliveryPolicy); | ||
} | ||
|
||
if (!string.IsNullOrEmpty(snsAttributes.Policy)) | ||
{ | ||
attributes.Add("Policy", snsAttributes.Policy); | ||
} | ||
} | ||
|
||
var createTopicRequest = new CreateTopicRequest(topicName) | ||
string name = topicName; | ||
if (snsSqsType == SnsSqsType.Fifo) | ||
{ | ||
Attributes = attributes, | ||
Tags = new List<Tag> {new Tag {Key = "Source", Value = "Brighter"}} | ||
}; | ||
name += ".fifo"; | ||
|
||
attributes.Add("FifoTopic", "true"); | ||
if (deduplication) | ||
{ | ||
attributes.Add("ContentBasedDeduplication", "true"); | ||
} | ||
} | ||
|
||
var createTopicRequest = new CreateTopicRequest(name) | ||
{ | ||
Attributes = attributes, | ||
Tags = [new Tag { Key = "Source", Value = "Brighter" }] | ||
}; | ||
|
||
//create topic is idempotent, so safe to call even if topic already exists | ||
var createTopic = snsClient.CreateTopicAsync(createTopicRequest).Result; | ||
|
||
if (!string.IsNullOrEmpty(createTopic.TopicArn)) | ||
ChannelTopicArn = createTopic.TopicArn; | ||
else | ||
throw new InvalidOperationException($"Could not create Topic topic: {topicName} on {_awsConnection.Region}"); | ||
throw new InvalidOperationException( | ||
$"Could not create Topic topic: {name} on {_awsConnection.Region}"); | ||
} | ||
|
||
private async Task ValidateTopicAsync(RoutingKey topic, TopicFindBy findTopicBy, OnMissingChannel onMissingChannel) | ||
private async Task ValidateTopicAsync(RoutingKey topic, TopicFindBy findTopicBy, | ||
OnMissingChannel onMissingChannel, SnsSqsType snsSqsType) | ||
{ | ||
IValidateTopic topicValidationStrategy = GetTopicValidationStrategy(findTopicBy); | ||
IValidateTopic topicValidationStrategy = GetTopicValidationStrategy(findTopicBy, snsSqsType); | ||
(bool exists, string topicArn) = await topicValidationStrategy.ValidateAsync(topic); | ||
if (exists) | ||
ChannelTopicArn = topicArn; | ||
|
@@ -91,16 +123,19 @@ private async Task ValidateTopicAsync(RoutingKey topic, TopicFindBy findTopicBy, | |
$"Topic validation error: could not find topic {topic}. Did you want Brighter to create infrastructure?"); | ||
} | ||
|
||
private IValidateTopic GetTopicValidationStrategy(TopicFindBy findTopicBy) | ||
private IValidateTopic GetTopicValidationStrategy(TopicFindBy findTopicBy, SnsSqsType type) | ||
{ | ||
switch (findTopicBy) | ||
{ | ||
case TopicFindBy.Arn: | ||
return new ValidateTopicByArn(_awsConnection.Credentials, _awsConnection.Region, _awsConnection.ClientConfigAction); | ||
return new ValidateTopicByArn(_awsConnection.Credentials, _awsConnection.Region, | ||
_awsConnection.ClientConfigAction); | ||
case TopicFindBy.Convention: | ||
return new ValidateTopicByArnConvention(_awsConnection.Credentials, _awsConnection.Region, _awsConnection.ClientConfigAction); | ||
return new ValidateTopicByArnConvention(_awsConnection.Credentials, _awsConnection.Region, | ||
_awsConnection.ClientConfigAction, type); | ||
case TopicFindBy.Name: | ||
return new ValidateTopicByName(_awsConnection.Credentials, _awsConnection.Region, _awsConnection.ClientConfigAction); | ||
return new ValidateTopicByName(_awsConnection.Credentials, _awsConnection.Region, | ||
_awsConnection.ClientConfigAction, type); | ||
default: | ||
throw new ConfigurationException("Unknown TopicFindBy used to determine how to read RoutingKey"); | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❌ New issue: Overall Code Complexity
This module has a mean cyclomatic complexity of 5.92 across 13 functions. The mean complexity threshold is 4
Suppress