Last active
August 4, 2024 03:28
-
-
Save gistlyn/223460e4b5cbb9c26299026b9e3a136d to your computer and use it in GitHub Desktop.
Use AWS SQS MQ
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
dotnet add package ServiceStack.Aws |
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
using Microsoft.Extensions.Configuration; | |
using Microsoft.Extensions.DependencyInjection; | |
using ServiceStack; | |
using ServiceStack.Messaging; | |
using ServiceStack.Aws; | |
using ServiceStack.Aws.Sqs; | |
[assembly: HostingStartup(typeof(MyApp.ConfigureMq))] | |
namespace MyApp; | |
/** | |
Register Services you want available via MQ in your AppHost, e.g: | |
var mqServer = appHost.Resolve<IMessageService>(); | |
mqServer.RegisterHandler<MyRequest>(ExecuteMessage); | |
*/ | |
public class ConfigureMq : IHostingStartup | |
{ | |
public void Configure(IWebHostBuilder builder) => builder | |
.ConfigureServices((context, services) => { | |
services.AddSingleton<IMessageService>(c => new SqsMqServer( | |
context.Configuration["AwsAccessKey"], | |
context.Configuration["AwsSecretKey"], | |
RegionEndpoint.USEast1) | |
{ | |
DisableBuffering = true, // Trade-off latency vs efficiency | |
}); | |
}) | |
.ConfigureAppHost(afterAppHostInit: appHost => { | |
appHost.Resolve<IMessageService>().Start(); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment