RedisMessenger 0.1.2
dotnet add package RedisMessenger --version 0.1.2
NuGet\Install-Package RedisMessenger -Version 0.1.2
<PackageReference Include="RedisMessenger" Version="0.1.2" />
<PackageVersion Include="RedisMessenger" Version="0.1.2" />
<PackageReference Include="RedisMessenger" />
paket add RedisMessenger --version 0.1.2
#r "nuget: RedisMessenger, 0.1.2"
#:package RedisMessenger@0.1.2
#addin nuget:?package=RedisMessenger&version=0.1.2
#tool nuget:?package=RedisMessenger&version=0.1.2
RedisMessenger .NET Client
The RedisMessenger .NET Client allows you to use Redis as a message broker to communicate between applications that implement the RedisMessenger protocol.
Install
You can install this library via NuGet:
dotnet add package RedisMessenger
Usage
RedisMessenger can be used either on its own or as an injectable service.
Standalone
If you don't use a hosted application or dependency injection container:
IRedisMessenger messenger = RedisMessenger.Create(configure =>
{
configure.RedisConfiguration = "localhost";
configure.ClientName = "my-messaging-client";
configure.ChannelPrefix = "cool-zone";
configure.RedisConfigure = redisOpts =>
{
redisOpts.AbortOnConnectFail = false;
};
configure.AddMessageHandler<MyMessageHandler>("my-message-channel");
});
DI container
If you want it to be injectable:
builder.Services.AddRedisMessenger(configure => ConfigureTheMessengerLikeAbove(configure));
Messages
Woooo, now let's send some messages or something:
var channel = messenger.GetMessageChannel<MyMessageRequest, MyMessageResponse>("my-message-channel");
await channel.SendAsync(new MyMessageRequest()); // Fire and forget, just like walking away from an explosion
try
{
MyMessageResponse? res = await channel.QueryAsync(new MyMessageRequest());
Console.WriteLine($"Knock knock, you got a message {res}");
}
catch (RedisMessengerResponseException ex)
{
Console.WriteLine($"Woopsies, something failed on the handler side :( {ex.Message}");
}
catch (OperationCanceledException)
{
Console.WriteLine("Probably worked on your machine but this is the cloud");
}
Message handlers
In the .NET library, you can have both typed and raw message handlers:
class MyRawMessageHandler : RedisMessenger.MessageHandler
{
protected override async Task<object?> HandleMessageAsync(System.Text.Json.JsonElement? payload)
{
// Exceptions will be reported to the message sender.
return await DoSomethingWithPayloadAsync(payload);
}
}
class MyMessageHandler : RedisMessenger.MessageHandler<RequestType, ResponseType>
{
private readonly ILogger _logger;
public MyMessageHandler(ILogger<MyMessageHandler> logger) => _logger = logger;
protected override async Task<ResponseType> HandleMessageAsync(RequestType? payload)
{
// JSON deserialization errors and exceptions will be reported to the message sender.
return await DoSomethingWithPayloadAsync(payload);
}
}
You can only register one message handler per channel.
Dependency injection
As you can see, other services can be injected into your message handlers. Each message has its own scope just like ASP.NET Core HTTP requests.
Redis configuration
This library is built upon StackExchange.Redis
and allows you to configure the Redis connection as you wish via RedisMessengerConfiguration.RedisConfigure
and RedisMessengerConfiguration.RedisConfiguration
.
License
MIT. Have fun.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Microsoft.Extensions.DependencyInjection (>= 8.0.0)
- Microsoft.Toolkit.HighPerformance (>= 7.1.2)
- StackExchange.Redis (>= 2.7.33)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.