Skip to content

Instantly share code, notes, and snippets.

@gistlyn
Last active August 4, 2024 03:28
Show Gist options
  • Save gistlyn/f047da23d16411849039945698be7380 to your computer and use it in GitHub Desktop.
Save gistlyn/f047da23d16411849039945698be7380 to your computer and use it in GitHub Desktop.
Use Azure Service Bus MQ
dotnet add package ServiceStack.Azure
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using ServiceStack;
using ServiceStack.Messaging;
using ServiceStack.Azure;
using ServiceStack.Azure.Messaging;
[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 ServiceBusMqServer(context.Configuration.GetConnectionString("ServiceBus")));
})
.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