Created
February 7, 2021 10:49
-
-
Save AbubakarSiddiq/014eff99043f34bdc2c6b8d372f39fba to your computer and use it in GitHub Desktop.
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
using GreenPipes; | |
using MassTransit; | |
using Microsoft.AspNetCore.Builder; | |
using Microsoft.AspNetCore.Hosting; | |
using Microsoft.AspNetCore.HttpsPolicy; | |
using Microsoft.AspNetCore.Mvc; | |
using Microsoft.Extensions.Configuration; | |
using Microsoft.Extensions.DependencyInjection; | |
using Microsoft.Extensions.Hosting; | |
using Microsoft.Extensions.Logging; | |
using Microsoft.OpenApi.Models; | |
using Order.Microservice.Consumers; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Threading.Tasks; | |
namespace Order.Microservice | |
{ | |
public class Startup | |
{ | |
public Startup(IConfiguration configuration) | |
{ | |
Configuration = configuration; | |
} | |
public IConfiguration Configuration { get; } | |
// This method gets called by the runtime. Use this method to add services to the container. | |
public void ConfigureServices(IServiceCollection services) | |
{ | |
services.AddMassTransit(x => | |
{ | |
x.AddConsumer<OrderConsumer>(); | |
x.AddBus(provider => Bus.Factory.CreateUsingRabbitMq(cur => | |
{ | |
cur.UseHealthCheck(provider); | |
cur.Host(new Uri("rabbitmq://localhost"), h => | |
{ | |
h.Username("guest"); | |
h.Password("guest"); | |
}); | |
cur.ReceiveEndpoint("orderQueue", oq => | |
{ | |
oq.PrefetchCount = 20; | |
oq.UseMessageRetry(r => r.Interval(2, 100)); | |
oq.ConfigureConsumer<OrderConsumer>(provider); | |
}); | |
})); | |
}); | |
services.AddMassTransitHostedService(); | |
services.AddControllers(); | |
services.AddSwaggerGen(c => | |
{ | |
c.SwaggerDoc("v1", new OpenApiInfo { Title = "Order.Microservice", Version = "v1" }); | |
}); | |
} | |
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. | |
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) | |
{ | |
if (env.IsDevelopment()) | |
{ | |
app.UseDeveloperExceptionPage(); | |
app.UseSwagger(); | |
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "Order.Microservice v1")); | |
} | |
app.UseHttpsRedirection(); | |
app.UseRouting(); | |
app.UseAuthorization(); | |
app.UseEndpoints(endpoints => | |
{ | |
endpoints.MapControllers(); | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment