-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from lenndewolten/feature/add-aws-sqs
Add AWS SQS
- Loading branch information
Showing
70 changed files
with
3,406 additions
and
3 deletions.
There are no files selected for viewing
7 changes: 5 additions & 2 deletions
7
.github/workflows/main-ci.yaml → .github/workflows/aqs-sqs-ci.yaml
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
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,50 @@ | ||
on: | ||
push: | ||
tags: | ||
- "aws-sqs_v[0-9]+.[0-9]+.[0-9]" | ||
- "aws-sqs_v[0-9]+.[0-9]+.[0-9]-preview*" | ||
- "aws-sqs_v[0-9]+.[0-9]+.[0-9]-beta*" | ||
- "aws-sqs_v[0-9]+.[0-9]+.[0-9]-alpha*" | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 15 | ||
steps: | ||
- name: Show the Github context for the triggered event | ||
run: echo "$GITHUB_CONTEXT" | ||
env: | ||
GITHUB_CONTEXT: ${{ toJson(github) }} | ||
- name: Set VERSION variable from tag | ||
run: echo "VERSION=${GITHUB_REF_NAME/aws-sqs_v/}" >> $GITHUB_ENV | ||
- name: Show default environment variables | ||
run: | | ||
echo "The job_id is: $GITHUB_JOB" # reference the default environment variables | ||
echo "The id of this action is: $GITHUB_ACTION" # reference the default environment variables | ||
echo "The run id is: $GITHUB_RUN_ID" | ||
echo "The GitHub Actor's username is: $GITHUB_ACTOR" | ||
echo "GitHub SHA: $GITHUB_SHA" | ||
echo "GitHub REF: $GITHUB_REF" | ||
echo "GitHub REF NAME: $GITHUB_REF_NAME" | ||
echo "VERSION: $VERSION" | ||
echo "dotnet version ${DOTNET_VERSION}" | ||
env: | ||
DOTNET_VERSION: ${{ vars.DOTNET_VERSION }} | ||
- uses: actions/checkout@v3 | ||
- name: Setup .NET Core SDK | ||
uses: actions/setup-dotnet@v3 | ||
with: | ||
dotnet-version: "6.x.x" | ||
|
||
- name: Install dependencies | ||
run: dotnet restore | ||
- name: Build | ||
run: dotnet build --configuration Release /p:Version=${VERSION} --no-restore | ||
- name: Test | ||
run: dotnet test --configuration Release /p:Version=${VERSION} --no-build | ||
- name: Pack | ||
run: dotnet pack lib/Dequeueable.AmazonSQS/Dequeueable.AmazonSQS.csproj --configuration Release /p:Version=${VERSION} --no-build --output . | ||
- name: Push | ||
run: dotnet nuget push Dequeueable.AmazonSQS.${VERSION}.nupkg --source https://api.nuget.org/v3/index.json --api-key ${NUGET_KEY} | ||
env: | ||
NUGET_KEY: ${{secrets.NUGET_KEY}} |
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
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
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,85 @@ | ||
using Dequeueable.AmazonSQS.Services.Hosts; | ||
using Dequeueable.AmazonSQS.Services.Queues; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.DependencyInjection.Extensions; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace Dequeueable.AmazonSQS.Configurations | ||
{ | ||
internal class HostBuilder : IDequeueableHostBuilder | ||
{ | ||
private readonly IServiceCollection _services; | ||
|
||
public HostBuilder(IServiceCollection services) | ||
{ | ||
_services = services; | ||
} | ||
|
||
public IDequeueableHostBuilder RunAsJob(Action<HostOptions>? options = null) | ||
{ | ||
_services.AddOptions<HostOptions>().BindConfiguration(HostOptions.Dequeueable) | ||
.ValidateDataAnnotations() | ||
.ValidateOnStart(); | ||
|
||
if (options is not null) | ||
{ | ||
_services.Configure(options); | ||
} | ||
|
||
_services.AddHostedService<JobHost>(); | ||
_services.AddSingleton<IHostExecutor, JobExecutor>(); | ||
|
||
_services.TryAddSingleton<IHostOptions>(provider => | ||
{ | ||
var opt = provider.GetRequiredService<IOptions<HostOptions>>(); | ||
return opt.Value; | ||
}); | ||
|
||
return this; | ||
} | ||
|
||
public IDequeueableHostBuilder RunAsListener(Action<ListenerHostOptions>? options = null) | ||
{ | ||
_services.AddOptions<ListenerHostOptions>().BindConfiguration(HostOptions.Dequeueable) | ||
.Validate(ListenerHostOptions.ValidatePollingInterval, $"The '{nameof(ListenerHostOptions.MinimumPollingIntervalInMilliseconds)}' must not be greater than the '{nameof(ListenerHostOptions.MaximumPollingIntervalInMilliseconds)}'.") | ||
.Validate(ListenerHostOptions.ValidateNewBatchThreshold, $"The '{nameof(ListenerHostOptions.NewBatchThreshold)}' must not be greater than the '{nameof(ListenerHostOptions.BatchSize)}'.") | ||
.ValidateDataAnnotations() | ||
.ValidateOnStart(); | ||
|
||
if (options is not null) | ||
{ | ||
_services.Configure(options); | ||
} | ||
|
||
_services.AddHostedService<QueueListenerHost>(); | ||
_services.AddSingleton<IHostExecutor, QueueListenerExecutor>(); | ||
|
||
_services.TryAddSingleton<IHostOptions>(provider => | ||
{ | ||
var opt = provider.GetRequiredService<IOptions<ListenerHostOptions>>(); | ||
return opt.Value; | ||
}); | ||
|
||
return this; | ||
} | ||
|
||
public IDequeueableHostBuilder AsSingleton() | ||
{ | ||
_services.AddTransient<SingletonManager>(); | ||
_services.AddTransient<QueueMessageExecutor>(); | ||
_services.AddTransient<IQueueMessageExecutor>(provider => | ||
{ | ||
var singletonManager = provider.GetRequiredService<SingletonManager>(); | ||
var executor = provider.GetRequiredService<QueueMessageExecutor>(); | ||
return new SingletonQueueMessageExecutor(executor, singletonManager); | ||
}); | ||
|
||
_services.PostConfigure<HostOptions>(options => options.AttributeNames = options.AttributeNames.Concat(new List<string> { "MessageGroupId" }).ToList()); | ||
_services.PostConfigure<ListenerHostOptions>(options => options.AttributeNames = options.AttributeNames.Concat(new List<string> { "MessageGroupId" }).ToList()); | ||
_services.PostConfigure<ListenerHostOptions>(options => options.NewBatchThreshold = 0); | ||
|
||
return this; | ||
} | ||
} | ||
} |
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,49 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
namespace Dequeueable.AmazonSQS.Configurations | ||
{ | ||
/// <summary> | ||
/// HostOptions to configure the settings of the host | ||
/// </summary> | ||
public class HostOptions : IHostOptions | ||
{ | ||
private List<string> _attributeNames = new(); | ||
|
||
/// <summary> | ||
/// Constant string used to bind the appsettings.*.json | ||
/// </summary> | ||
public static string Dequeueable => nameof(Dequeueable); | ||
|
||
/// <summary> | ||
/// The URL of the Amazon SQS queue from which messages are received. | ||
/// </summary> | ||
[Required(AllowEmptyStrings = false, ErrorMessage = "{0} cannot be empty.")] | ||
public string QueueUrl { get; set; } = string.Empty; | ||
|
||
/// <summary> | ||
/// The maximum number of messages processed in parallel. Valid values: 1 to 10. | ||
/// </summary> | ||
[Range(1, 10, | ||
ErrorMessage = "Value for {0} must be between {1} and {2}.")] | ||
public int BatchSize { get; set; } = 4; | ||
|
||
/// <summary> | ||
/// The timeout after the queue message is visible again for other services. Valid values: 30 to 43200 (12 hours) seconds. | ||
/// </summary> | ||
[Range(30, 43200, | ||
ErrorMessage = "Value for {0} must be between {1} and {2}.")] | ||
public int VisibilityTimeoutInSeconds { get; set; } = 300; | ||
|
||
/// <summary> | ||
/// A list of attributes that need to be returned along with each message <see cref="Amazon.SQS.Model.Message.Attributes"/>. | ||
/// </summary> | ||
public List<string> AttributeNames | ||
{ | ||
get => _attributeNames.Distinct().ToList(); | ||
set | ||
{ | ||
_attributeNames = value ?? new(); | ||
} | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
lib/Dequeueable.AmazonSQS/Configurations/IDequeueableHostBuilder.cs
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,26 @@ | ||
namespace Dequeueable.AmazonSQS.Configurations | ||
{ | ||
/// <summary> | ||
/// Interface to builds and setup the dequeueable host | ||
/// </summary> | ||
public interface IDequeueableHostBuilder | ||
{ | ||
/// <summary> | ||
/// Runs the function as a Distributed Singleton. Queue messages containing the same MessageGroupId will not run in parallel <see href="https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/using-messagegroupid-property.html"/> | ||
/// </summary> | ||
/// <returns><see cref="IDequeueableHostBuilder"/></returns> | ||
IDequeueableHostBuilder AsSingleton(); | ||
/// <summary> | ||
/// The application will run as a job, from start to finish, and will automatically shutdown when the messages are executed. | ||
/// </summary> | ||
/// <param name="options">Action to configure the <see cref="HostOptions"/></param> | ||
/// <returns><see cref="IDequeueableHostBuilder"/></returns> | ||
IDequeueableHostBuilder RunAsJob(Action<HostOptions>? options = null); | ||
/// <summary> | ||
/// The application will run as a listener, the queue will periodically be polled for new message. | ||
/// </summary> | ||
/// <param name="options">Action to configure the <see cref="ListenerHostOptions"/></param> | ||
/// <returns><see cref="IDequeueableHostBuilder"/></returns> | ||
IDequeueableHostBuilder RunAsListener(Action<ListenerHostOptions>? options = null); | ||
} | ||
} |
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,25 @@ | ||
namespace Dequeueable.AmazonSQS.Configurations | ||
{ | ||
/// <summary> | ||
/// Use the IHostOptions to configure the settings of the host | ||
/// </summary> | ||
public interface IHostOptions | ||
{ | ||
/// <summary> | ||
/// The maximum number of messages processed in parallel. Valid values: 1 to 10. | ||
/// </summary> | ||
int BatchSize { get; set; } | ||
/// <summary> | ||
/// The timeout after the queue message is visible again for other services. Valid values: 30 to 43200 (12 hours) seconds. | ||
/// </summary> | ||
int VisibilityTimeoutInSeconds { get; set; } | ||
/// <summary> | ||
/// The URL of the Amazon SQS queue from which messages are received. | ||
/// </summary> | ||
string QueueUrl { get; set; } | ||
/// <summary> | ||
/// A list of attributes that need to be returned along with each message <see cref="Amazon.SQS.Model.Message.Attributes"/>. | ||
/// </summary> | ||
List<string> AttributeNames { get; set; } | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
lib/Dequeueable.AmazonSQS/Configurations/ListenerHostOptions.cs
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,41 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
namespace Dequeueable.AmazonSQS.Configurations | ||
{ | ||
/// <summary> | ||
/// HostOptions to configure the settings of the host | ||
/// </summary> | ||
public class ListenerHostOptions : HostOptions | ||
{ | ||
/// <summary> | ||
/// The threshold at which a new batch of messages will be fetched. | ||
/// </summary> | ||
public int? NewBatchThreshold { get; set; } | ||
|
||
/// <summary> | ||
/// The minimum polling interval to check the queue for new messages. | ||
/// </summary> | ||
[Range(1, long.MaxValue, ErrorMessage = "Value for {0} must be lower than {1}.")] | ||
public long MinimumPollingIntervalInMilliseconds { get; set; } = 5; | ||
|
||
/// <summary> | ||
/// The maximum polling interval to check the queue for new messages. | ||
/// </summary> | ||
[Range(1, long.MaxValue, ErrorMessage = "Value for {0} must be lower than {1}.")] | ||
public long MaximumPollingIntervalInMilliseconds { get; set; } = 10000; | ||
|
||
/// <summary> | ||
/// The delta used to randomize the polling interval. | ||
/// </summary> | ||
public TimeSpan? DeltaBackOff { get; set; } | ||
|
||
internal static bool ValidatePollingInterval(ListenerHostOptions options) | ||
{ | ||
return options.MinimumPollingIntervalInMilliseconds < options.MaximumPollingIntervalInMilliseconds; | ||
} | ||
internal static bool ValidateNewBatchThreshold(ListenerHostOptions options) | ||
{ | ||
return options.NewBatchThreshold is null || options.NewBatchThreshold <= options.BatchSize; | ||
} | ||
} | ||
} |
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,35 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<PackageId>Dequeueable.AmazonSQS</PackageId> | ||
<Version>1.0.0</Version> | ||
<Authors>Lennart ten Wolde</Authors> | ||
<PackageTags>Amazon;AWS;Simple Queue Service;SQS;Queues;Queue;QueueMessage;QueueMessages;Message;Events;Event</PackageTags> | ||
<Title>Dequeueable for AWS Simple Queue Service library</Title> | ||
<Description> | ||
This client library simplifies dequeuing queue messages from Amazon Simple Queue Service. It makes it easy to retrieve messages from the queue: dequeueing, exception handling and distributed singleton are handled for you. | ||
</Description> | ||
<PackageLicenseExpression>MIT</PackageLicenseExpression> | ||
<PackageReadmeFile>./README.md</PackageReadmeFile> | ||
<RepositoryUrl>https://github.com/lenndewolten/Dequeueable</RepositoryUrl> | ||
<RepositoryType>Git</RepositoryType> | ||
<ProjectUrl>https://github.com/lenndewolten/Dequeueable</ProjectUrl> | ||
<PackageProjectUrl>https://github.com/lenndewolten/Dequeueable</PackageProjectUrl> | ||
<GenerateDocumentationFile>true</GenerateDocumentationFile> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="AWSSDK.SQS" Version="3.7.100.62" /> | ||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" /> | ||
<PackageReference Include="Microsoft.Extensions.Options.DataAnnotations" Version="6.0.0" /> | ||
<PackageReference Include="System.Memory.Data" Version="1.0.2" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<InternalsVisibleTo Include="$(AssemblyName).UnitTests" /> | ||
<InternalsVisibleTo Include="$(AssemblyName).IntegrationTests" /> | ||
<InternalsVisibleTo Include="DynamicProxyGenAssembly2" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="README.md" /> | ||
</ItemGroup> | ||
</Project> |
Oops, something went wrong.