gabrielweyer-pre-release - BeanstalkWorker.SimpleRouting 1.0.3-dotnet-3-1-0004

Allows to route a SQS message to a specific endpoint on the Worker instead of having a single endpoint handling all the messages.

PM> Install-Package BeanstalkWorker.SimpleRouting -Version 1.0.3-dotnet-3-1-0004 -Source https://www.myget.org/F/gabrielweyer-pre-release/api/v3/index.json

Copy to clipboard

> nuget.exe install BeanstalkWorker.SimpleRouting -Version 1.0.3-dotnet-3-1-0004 -Source https://www.myget.org/F/gabrielweyer-pre-release/api/v3/index.json

Copy to clipboard

> dotnet add package BeanstalkWorker.SimpleRouting --version 1.0.3-dotnet-3-1-0004 --source https://www.myget.org/F/gabrielweyer-pre-release/api/v3/index.json

Copy to clipboard
<PackageReference Include="BeanstalkWorker.SimpleRouting" Version="1.0.3-dotnet-3-1-0004" />
Copy to clipboard
source https://www.myget.org/F/gabrielweyer-pre-release/api/v3/index.json

nuget BeanstalkWorker.SimpleRouting  ~> 1.0.3-dotnet-3-1-0004
Copy to clipboard

> choco install BeanstalkWorker.SimpleRouting --version 1.0.3-dotnet-3-1-0004 --source https://www.myget.org/F/gabrielweyer-pre-release/api/v2

Copy to clipboard
Import-Module PowerShellGet
Register-PSRepository -Name "gabrielweyer-pre-release" -SourceLocation "https://www.myget.org/F/gabrielweyer-pre-release/api/v2"
Install-Module -Name "BeanstalkWorker.SimpleRouting" -RequiredVersion "1.0.3-dotnet-3-1-0004" -Repository "gabrielweyer-pre-release" -AllowPreRelease
Copy to clipboard

Browse the sources in this package using Visual Studio or WinDbg by configuring the following symbol server URL: https://www.myget.org/F/gabrielweyer-pre-release/api/v2/symbolpackage/


Elastic Beanstalk Worker Simple Routing

Package Release Pre-release
BeanstalkWorker.SimpleRouting NuGet MyGet
CI Status Platform(s) Framework(s) Test Framework(s)
AppVeyor Build Status Windows nestandard2.0 netcoreapp3.1

Allows to route a SQS message to a specific endpoint on the Worker instead of having a single endpoint handling all the messages.

Relies on the SQS message attributes. This is distributed via a NuGet package but the implementation is so simple that you can just copy the classes into your own solution if that works better for you.

How it works

Web Tier - Set the attribute on the message

// Instantiate your model
StronglyTypedMessage model = new StronglyTypedMessage();

var sendMessageRequest = new SendMessageRequest
{
  // Serialize your model as JSON (you can use Newtonsoft.Json if you prefer)
  MessageBody = System.Text.Json.JsonSerializer.Serialize(model)
  // Set the QueueUrl and other properties as you see fit
};

// AddRoutingAttribute is an extension method in the "BeanstalkWorker.SimpleRouting" namespace
sendMessageRequest.MessageAttributes.AddRoutingAttribute("task-name");

Web sample project

A sample Web app is provided in samples/SampleWeb.

You can send two distinct types of messages by hitting two different endpoints:

  • GET http://localhost:5000/send/work
  • GET http://localhost:5000/send/nothing
Configuration

Create a iAM user (if you don't have one already) which has access to SQS.

You'll need to configure four settings using user secrets:

  • Aws:RegionSystemName - region code, for example ap-southeast-2
  • Aws:Queue:WorkerQueueUrl - URL of the SQS queue, for example https://sqs.ap-southeast-2.amazonaws.com/375985941080/dev-gabriel
  • Aws:Queue:AccessKeyId - this is the Access key ID of your iAM user
  • Aws:Queue:SecretAccessKey - this is the Secret access key of your iAM user

Worker Tier

Add the middleware to the Worker

In the Configure method of your Startup class:

public void Configure(IApplicationBuilder app)
{
    // The simple routing middleware needs to be added **before** configuring endpoint routing
    app.UseHeaderRouting();

    app.UseRouting();

    app.UseEndpoints(endpoint => endpoint.MapControllers());
}

Use a matching route on a Controller Action

// This is important, we do not want a prefix in front of the action's route
[Route("")]
[ApiController]
public class SomeController : ControllerBase
{
  // The route template has to match the argument given to AddRoutingAttribute
  [HttpPost("task-name")]
  public async Task<IActionResult> SomeMethod(StronglyTypedMessage model)
  {
      // Abbreviated for clarity
  }
}

Worker sample project

A sample Worker app is provided in samples/SampleWorker.

If you wish to run the Worker without deploying to AWS Beanstalk you can leverage my Beanstalk Seeder project.

Limitations

  • Does not support periodic tasks
    • It could be added fairly easily if required
  • netstandard2.0 and above only
    • .NET is a second class citizen on Elastic Beanstalk, for this reason I recommend creating Docker images so that you can take full advantage of the platform.
  • .NETStandard 2.0
    • AWSSDK.SQS (>= 3.3.102.118)
    • Microsoft.AspNetCore.Http.Abstractions (>= 2.2.0)
    • Microsoft.AspNetCore.Http.Features (>= 3.1.4)
    • Microsoft.Extensions.Logging.Abstractions (>= 3.1.4)
    • Microsoft.Extensions.Primitives (>= 3.1.4)
  • .NETStandard 2.0: 2.0.0.0

Owners

Gabriel Weyer

Authors

Gabriel Weyer

Project URL

https://github.com/gabrielweyer/simple-routing

License

Unknown

Tags

AWS Elastic Beanstalk Worker SQS Routing

Info

1 total downloads
0 downloads for version 1.0.3-dotnet-3-1-0004
Download (5.46 KB)
Download symbols (3.31 KB)
Found on the current feed only

Package history

Version Size Last updated Downloads Mirrored?
1.0.3-dotnet-3-1-0004 5.46 KB Sun, 31 May 2020 05:37:53 GMT 0
1.0.2-update-nuget-key0003 5.47 KB Sun, 13 Jan 2019 05:08:11 GMT 0
1.0.1-align-nuget-pack0001 5.47 KB Thu, 03 Jan 2019 12:17:37 GMT 0
0.4.1-fix-typo-to-bump0001 5.48 KB Thu, 03 Jan 2019 12:03:01 GMT 0
0.3.3-add-user-secrets0004 5.48 KB Thu, 03 Jan 2019 04:08:16 GMT 0
0.3.1-move-samples0001 5.46 KB Mon, 11 Jun 2018 05:51:08 GMT 0
0.2.6-netcore2-1-0002 5.47 KB Wed, 06 Jun 2018 11:03:23 GMT 0
0.2.5-update-nuget0001 5.42 KB Sun, 28 Jan 2018 02:50:46 GMT 0
0.2.2-debug-path0004 5.41 KB Sun, 28 Jan 2018 02:23:48 GMT 0
0.2.1-update-cake0001 5.38 KB Thu, 18 Jan 2018 07:27:24 GMT 0
0.1.2-worker0005 5.36 KB Wed, 17 Jan 2018 21:35:00 GMT 0
0.1.1-implementation0004 5.35 KB Wed, 17 Jan 2018 10:20:11 GMT 1
0.1.1-implementation0001 5.21 KB Tue, 16 Jan 2018 22:36:47 GMT 0