-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Invoke consumer-defined action when exceptions raised during consumpt…
…ion Redis streams (#1618) * #1611 Enhanced logging and error handling in RedisConsumer Added new unit tests for various functionalities and configurations. Improved code formatting and consistency across the project. * update summary * OnConsumeError Updates update CapRedisOptions with OnConsumeError option
- Loading branch information
1 parent
c29e8d6
commit 40a56d2
Showing
31 changed files
with
664 additions
and
265 deletions.
There are no files selected for viewing
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
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
75 changes: 36 additions & 39 deletions
75
samples/Samples.Redis.SqlServer/Controllers/HomeController.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,51 @@ | ||
using DotNetCore.CAP; | ||
using DotNetCore.CAP.Messages; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.Options; | ||
using System.Threading.Tasks; | ||
|
||
namespace Samples.Redis.SqlServer.Controllers | ||
namespace Samples.Redis.SqlServer.Controllers; | ||
|
||
[ApiController] | ||
[Route("[controller]/[action]")] | ||
public class HomeController : ControllerBase | ||
{ | ||
[ApiController] | ||
[Route("[controller]/[action]")] | ||
public class HomeController : ControllerBase | ||
private readonly ILogger<HomeController> _logger; | ||
private readonly ICapPublisher _publisher; | ||
private readonly IOptions<CapOptions> _options; | ||
|
||
public HomeController(ILogger<HomeController> logger, ICapPublisher publisher, IOptions<CapOptions> options) | ||
{ | ||
private readonly ILogger<HomeController> _logger; | ||
private readonly ICapPublisher _publisher; | ||
private readonly IOptions<CapOptions> _options; | ||
|
||
public HomeController(ILogger<HomeController> logger, ICapPublisher publisher, IOptions<CapOptions> options) | ||
{ | ||
_logger = logger; | ||
_publisher = publisher; | ||
this._options = options; | ||
} | ||
|
||
[HttpGet] | ||
public async Task Publish([FromQuery] string message = "test-message") | ||
{ | ||
await _publisher.PublishAsync(message, new Person() { Age = 11, Name = "James" }); | ||
} | ||
|
||
[CapSubscribe("test-message")] | ||
[CapSubscribe("test-message-1")] | ||
[CapSubscribe("test-message-2")] | ||
[CapSubscribe("test-message-3")] | ||
[NonAction] | ||
public void Subscribe(Person p, [FromCap] CapHeader header) | ||
{ | ||
_logger.LogInformation($"{header[Headers.MessageName]} subscribed with value --> " + p); | ||
} | ||
_logger = logger; | ||
_publisher = publisher; | ||
this._options = options; | ||
} | ||
|
||
[HttpGet] | ||
public async Task Publish([FromQuery] string message = "test-message") | ||
{ | ||
await _publisher.PublishAsync(message, new Person() { Age = 11, Name = "James" }); | ||
} | ||
|
||
public class Person | ||
[CapSubscribe("test-message")] | ||
[CapSubscribe("test-message-1")] | ||
[CapSubscribe("test-message-2")] | ||
[CapSubscribe("test-message-3")] | ||
[NonAction] | ||
public void Subscribe(Person p, [FromCap] CapHeader header) | ||
{ | ||
public string Name { get; set; } | ||
_logger.LogInformation($"{header[Headers.MessageName]} subscribed with value --> " + p); | ||
} | ||
|
||
public int Age { get; set; } | ||
} | ||
|
||
public class Person | ||
{ | ||
public string Name { get; set; } | ||
|
||
public override string ToString() | ||
{ | ||
return "Name:" + Name + ", Age:" + Age; | ||
} | ||
public int Age { get; set; } | ||
|
||
public override string ToString() | ||
{ | ||
return "Name:" + Name + ", Age:" + Age; | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,46 @@ | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.Hosting; | ||
|
||
namespace Samples.Redis.SqlServer | ||
{ | ||
public class Program | ||
using StackExchange.Redis; | ||
|
||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
builder.Services | ||
.AddControllers(); | ||
|
||
builder.Services | ||
.AddEndpointsApiExplorer(); | ||
builder.Services | ||
.AddSwaggerGen(); | ||
|
||
builder.Services | ||
.AddCap(options => | ||
{ | ||
public static void Main(string[] args) | ||
options.UseRedis(redis => | ||
{ | ||
CreateHostBuilder(args).Build().Run(); | ||
} | ||
|
||
public static IHostBuilder CreateHostBuilder(string[] args) => | ||
Host.CreateDefaultBuilder(args) | ||
.ConfigureWebHostDefaults(webBuilder => | ||
{ | ||
webBuilder.UseStartup<Startup>(); | ||
}); | ||
} | ||
redis.Configuration = ConfigurationOptions.Parse("redis-node-0:6379,password=cap"); | ||
redis.OnConsumeError = context => | ||
{ | ||
throw new InvalidOperationException(""); | ||
}; | ||
}); | ||
|
||
options.UseSqlServer("Server=db;Database=master;User=sa;Password=P@ssw0rd;Encrypt=False"); | ||
|
||
options.UseDashboard(); | ||
|
||
}); | ||
|
||
var app = builder.Build(); | ||
|
||
if (app.Environment.IsDevelopment()) | ||
{ | ||
app.UseSwagger(); | ||
app.UseSwaggerUI(); | ||
} | ||
|
||
app.UseHttpsRedirection(); | ||
|
||
app.UseAuthorization(); | ||
|
||
app.MapControllers(); | ||
|
||
app.Run(); |
33 changes: 18 additions & 15 deletions
33
samples/Samples.Redis.SqlServer/Samples.Redis.SqlServer.csproj
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<UserSecretsId>eb622624-fbc4-46d0-b006-dfe8e66df5bb</UserSecretsId> | ||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS> | ||
<DockerfileContext>..\..</DockerfileContext> | ||
<DockerComposeProjectPath>..\..\docker-compose.dcproj</DockerComposeProjectPath> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\DotNetCore.CAP.RedisStreams\DotNetCore.CAP.RedisStreams.csproj" /> | ||
<ProjectReference Include="..\..\src\DotNetCore.CAP.SqlServer\DotNetCore.CAP.SqlServer.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> | ||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<UserSecretsId>eb622624-fbc4-46d0-b006-dfe8e66df5bb</UserSecretsId> | ||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<DockerfileContext>..\..</DockerfileContext> | ||
<DockerComposeProjectPath>..\..\docker-compose.dcproj</DockerComposeProjectPath> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.0" /> | ||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\DotNetCore.CAP.Dashboard\DotNetCore.CAP.Dashboard.csproj" /> | ||
<ProjectReference Include="..\..\src\DotNetCore.CAP.RedisStreams\DotNetCore.CAP.RedisStreams.csproj" /> | ||
<ProjectReference Include="..\..\src\DotNetCore.CAP.SqlServer\DotNetCore.CAP.SqlServer.csproj" /> | ||
</ItemGroup> | ||
</Project> |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,5 +6,5 @@ | |
"Microsoft.Hosting.Lifetime": "Information" | ||
} | ||
}, | ||
"AllowedHosts": "*" | ||
"AllowedHosts": "*" | ||
} |
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
Oops, something went wrong.