Last active
August 18, 2019 14:28
-
-
Save gistlyn/27e9d7ba79a318abb1e018396be2c123 to your computer and use it in GitHub Desktop.
Use Redis MQ
This file contains hidden or 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.Redis |
This file contains hidden or 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.Redis; | |
using ServiceStack.Messaging.Redis; | |
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 RedisMqServer(c.Resolve<IRedisClientsManager>())); | |
} | |
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