gabrielweyer-pre-release - BeanstalkWorker.SimpleRouting 1.0.2-update-nuget-key0003

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.2-update-nuget-key0003 -Source https://www.myget.org/F/gabrielweyer-pre-release/api/v3/index.json

Copy to clipboard

> nuget.exe install BeanstalkWorker.SimpleRouting -Version 1.0.2-update-nuget-key0003 -Source https://www.myget.org/F/gabrielweyer-pre-release/api/v3/index.json

Copy to clipboard

> dotnet add package BeanstalkWorker.SimpleRouting --version 1.0.2-update-nuget-key0003 --source https://www.myget.org/F/gabrielweyer-pre-release/api/v3/index.json

Copy to clipboard
<PackageReference Include="BeanstalkWorker.SimpleRouting" Version="1.0.2-update-nuget-key0003" />
Copy to clipboard
source https://www.myget.org/F/gabrielweyer-pre-release/api/v3/index.json

nuget BeanstalkWorker.SimpleRouting  ~> 1.0.2-update-nuget-key0003
Copy to clipboard

> choco install BeanstalkWorker.SimpleRouting --version 1.0.2-update-nuget-key0003 --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.2-update-nuget-key0003" -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/symbols/


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 netcoreapp2.2.0

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
  MessageBody = JsonConvert.SerializeObject(model)
  // Set the QueueUrl
};

// AddRoutingAttribute is an extension method
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 /send/work
  • GET /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, either using user secrets (preferred way as they'll be shared with the sample worker), appsettings.json or via environment variables:

  • 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_ACCESS_KEY_ID - this is the Access key ID of your iAM user
  • AWS_SECRET_ACCESS_KEY - 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)
{
    app.UseHeaderRouting();

    // Abbreviated for clarity
}

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("")]
public class SomeController : Controller
{
  // The route 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.3.44)
    • Microsoft.AspNetCore.Http.Abstractions (>= 2.2.0)
    • Microsoft.AspNetCore.Http.Features (>= 2.2.0)
    • Microsoft.Extensions.Logging.Abstractions (>= 2.2.0)
    • Microsoft.Extensions.Primitives (>= 2.2.0)
  • .NETStandard 2.0: 2.0.0.0

                        
Assembly Assembly hash Match
/lib/netstandard2.0/beanstalkworker.simplerouting.dll 581497d1a20a41d983b2d1f9d36d306cFFFFFFFF

Owners

Gabriel Weyer

Authors

Gabriel Weyer

Project URL

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

License

Unknown

Tags

AWS Elastic Beanstalk Worker SQS Routing

Info

0 total downloads
0 downloads for version 1.0.2-update-nuget-key0003
Download (5.47 KB)
Download symbols (6.37 KB)
Found on the current feed only

Package history

Version Size Last updated Downloads Mirrored?
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 0
0.1.1-implementation0001 5.21 KB Tue, 16 Jan 2018 22:36:47 GMT 0