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.
 
 
 

41 line
1.3 KiB

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