Skip to content

Instantly share code, notes, and snippets.

@gistlyn
Last active August 18, 2019 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gistlyn/0bbcb8db96236f4f90aafe4cd3812244 to your computer and use it in GitHub Desktop.
Save gistlyn/0bbcb8db96236f4f90aafe4cd3812244 to your computer and use it in GitHub Desktop.
Use Azure Service Bus
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;
namespace MyApp
{
/**
Register Services you want available via MQ in your AppHost, e.g:
var mqServer = container.Resolve<IMessageService>();
mqServer.RegisterHandler<MyRequest>(ExecuteMessage);
*/
public class ConfigureMq : IConfigureServices, IAfterInitAppHost
{
IConfiguration Configuration { get; }
public ConfigureMq(IConfiguration configuration) => Configuration = configuration;
public void Configure(IServiceCollection services)
{
services.AddSingleton<IMessageService>(c =>
new ServiceBusMqServer(Configuration.GetConnectionString("ServiceBus")));
}
public void AfterInit(IAppHost appHost)
{
appHost.Resolve<IMessageService>().Start();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment