You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

45 lines
1.4 KiB

  1. using System;
  2. using System.Text.Encodings.Web;
  3. using System.Text.Unicode;
  4. using DotNetCore.CAP.Messages;
  5. using Microsoft.AspNetCore.Builder;
  6. using Microsoft.Extensions.DependencyInjection;
  7. using Microsoft.Extensions.Logging;
  8. namespace Sample.RabbitMQ.SqlServer
  9. {
  10. public class Startup
  11. {
  12. public void ConfigureServices(IServiceCollection services)
  13. {
  14. services.AddDbContext<AppDbContext>();
  15. services.AddCap(x =>
  16. {
  17. x.UseEntityFramework<AppDbContext>();
  18. x.UseRabbitMQ("");
  19. x.UseDashboard();
  20. x.FailedRetryCount = 5;
  21. x.FailedThresholdCallback = failed =>
  22. {
  23. var logger = failed.ServiceProvider.GetService<ILogger<Startup>>();
  24. logger.LogError($@"A message of type {failed.MessageType} failed after executing {x.FailedRetryCount} several times,
  25. requiring manual troubleshooting. Message name: {failed.Message.GetName()}");
  26. };
  27. x.JsonSerializerOptions.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All);
  28. });
  29. services.AddControllers();
  30. }
  31. public void Configure(IApplicationBuilder app)
  32. {
  33. app.UseRouting();
  34. app.UseEndpoints(endpoints =>
  35. {
  36. endpoints.MapControllers();
  37. });
  38. }
  39. }
  40. }