Commit 27698a9a authored by Savorboard's avatar Savorboard

remove cap.UseDashboard. It's will be automatically enabled by registerd services.

parent 778c3529
...@@ -4,10 +4,7 @@ using System.Linq; ...@@ -4,10 +4,7 @@ using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
namespace Sample.RabbitMQ.PostgreSql namespace Sample.RabbitMQ.PostgreSql
{ {
...@@ -16,7 +13,25 @@ namespace Sample.RabbitMQ.PostgreSql ...@@ -16,7 +13,25 @@ namespace Sample.RabbitMQ.PostgreSql
// This method gets called by the runtime. Use this method to add services to the container. // This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services) public void ConfigureServices(IServiceCollection services)
{ {
services.AddCap(x =>
{
x.UseEntityFramework<AppDbContext>();
x.UseRabbitMQ(z =>
{
z.HostName = "192.168.2.206";
z.UserName = "admin";
z.Password = "123123";
});
x.UseDashboard();
x.UseDiscovery(d =>
{
d.DiscoveryServerHostName = "localhost";
d.DiscoveryServerProt = 8500;
d.CurrentNodeHostName = "localhost";
d.CurrentNodePort = 5800;
d.NodeName = "CAP一号节点";
});
});
services.AddMvc(); services.AddMvc();
} }
...@@ -24,6 +39,8 @@ namespace Sample.RabbitMQ.PostgreSql ...@@ -24,6 +39,8 @@ namespace Sample.RabbitMQ.PostgreSql
public void Configure(IApplicationBuilder app, IHostingEnvironment env) public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{ {
app.UseMvc(); app.UseMvc();
app.UseCap();
} }
} }
} }
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Sample.RabbitMQ.SqlServer.Services; using Sample.RabbitMQ.SqlServer.Services;
...@@ -26,7 +25,7 @@ namespace Sample.RabbitMQ.SqlServer ...@@ -26,7 +25,7 @@ namespace Sample.RabbitMQ.SqlServer
z.UserName = "admin"; z.UserName = "admin";
z.Password = "123123"; z.Password = "123123";
}); });
x.UseDashboard(); x.UseDashboard(d => { d.StatsPollingInterval = 1000000; });
x.UseDiscovery(d => x.UseDiscovery(d =>
{ {
d.DiscoveryServerHostName = "localhost"; d.DiscoveryServerHostName = "localhost";
...@@ -48,8 +47,6 @@ namespace Sample.RabbitMQ.SqlServer ...@@ -48,8 +47,6 @@ namespace Sample.RabbitMQ.SqlServer
app.UseMvc(); app.UseMvc();
app.UseCap(); app.UseCap();
app.UseCapDashboard();
} }
} }
} }
\ No newline at end of file
...@@ -26,24 +26,18 @@ namespace Microsoft.AspNetCore.Builder ...@@ -26,24 +26,18 @@ namespace Microsoft.AspNetCore.Builder
CheckRequirement(app); CheckRequirement(app);
var provider = app.ApplicationServices; var provider = app.ApplicationServices;
var bootstrapper = provider.GetRequiredService<IBootstrapper>(); var bootstrapper = provider.GetRequiredService<IBootstrapper>();
bootstrapper.BootstrapAsync(); bootstrapper.BootstrapAsync();
return app;
}
///<summary> if (provider.GetService<DashboardOptions>() != null)
/// Enables cap dashboard for the current application {
/// </summary> if (provider.GetService<DiscoveryOptions>() != null)
/// <param name="app">The <see cref="IApplicationBuilder"/> instance this method extends.</param>
/// <returns>The <see cref="IApplicationBuilder"/> instance this method extends.</returns>
public static IApplicationBuilder UseCapDashboard(this IApplicationBuilder app)
{ {
if (app == null) throw new ArgumentNullException(nameof(app));
CheckRequirement(app);
app.UseMiddleware<GatewayProxyMiddleware>(); app.UseMiddleware<GatewayProxyMiddleware>();
}
app.UseMiddleware<DashboardMiddleware>(); app.UseMiddleware<DashboardMiddleware>();
}
return app; return app;
} }
......
...@@ -25,9 +25,9 @@ namespace DotNetCore.CAP ...@@ -25,9 +25,9 @@ namespace DotNetCore.CAP
public Task Invoke(HttpContext context) public Task Invoke(HttpContext context)
{ {
if (context.Request.Path.StartsWithSegments(_options.PathMatch, if (!context.Request.Path.StartsWithSegments(_options.PathMatch,
out var matchedPath, out var remainingPath)) out var matchedPath, out var remainingPath)) return _next(context);
{
// Update the path // Update the path
var path = context.Request.Path; var path = context.Request.Path;
var pathBase = context.Request.PathBase; var pathBase = context.Request.PathBase;
...@@ -65,10 +65,5 @@ namespace DotNetCore.CAP ...@@ -65,10 +65,5 @@ namespace DotNetCore.CAP
context.Request.Path = path; context.Request.Path = path;
} }
} }
else
{
return _next(context);
}
}
} }
} }
...@@ -46,11 +46,18 @@ namespace DotNetCore.CAP.Dashboard.GatewayProxy ...@@ -46,11 +46,18 @@ namespace DotNetCore.CAP.Dashboard.GatewayProxy
var request = context.Request; var request = context.Request;
var pathMatch = discoveryOptions.MatchPath; var pathMatch = discoveryOptions.MatchPath;
var isCapRequest = request.Path.StartsWithSegments(new PathString(pathMatch)); var isCapRequest = request.Path.StartsWithSegments(new PathString(pathMatch));
if (!isCapRequest)
{
await _next.Invoke(context);
}
else
{
//For performance reasons, we need to put this functionality in the else
var isSwitchNode = request.Cookies.TryGetValue(NodeCookieName, out string requestNodeId); var isSwitchNode = request.Cookies.TryGetValue(NodeCookieName, out string requestNodeId);
var isCurrentNode = discoveryOptions.NodeId.ToString() == requestNodeId; var isCurrentNode = discoveryOptions.NodeId.ToString() == requestNodeId;
var isNodesPage = request.Path.StartsWithSegments(new PathString(pathMatch + "/nodes"));
if (!isCapRequest || !isSwitchNode || isCurrentNode) if (!isSwitchNode || isCurrentNode || isNodesPage)
{ {
await _next.Invoke(context); await _next.Invoke(context);
} }
...@@ -70,7 +77,7 @@ namespace DotNetCore.CAP.Dashboard.GatewayProxy ...@@ -70,7 +77,7 @@ namespace DotNetCore.CAP.Dashboard.GatewayProxy
await SetResponseOnHttpContext(context, response); await SetResponseOnHttpContext(context, response);
} }
catch(Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex.Message); _logger.LogError(ex.Message);
} }
...@@ -82,6 +89,7 @@ namespace DotNetCore.CAP.Dashboard.GatewayProxy ...@@ -82,6 +89,7 @@ namespace DotNetCore.CAP.Dashboard.GatewayProxy
} }
} }
} }
}
public async Task SetResponseOnHttpContext(HttpContext context, HttpResponseMessage response) public async Task SetResponseOnHttpContext(HttpContext context, HttpResponseMessage response)
{ {
...@@ -90,7 +98,6 @@ namespace DotNetCore.CAP.Dashboard.GatewayProxy ...@@ -90,7 +98,6 @@ namespace DotNetCore.CAP.Dashboard.GatewayProxy
AddHeaderIfDoesntExist(context, httpResponseHeader); AddHeaderIfDoesntExist(context, httpResponseHeader);
} }
var stringContent = await response.Content.ReadAsStringAsync();
var content = await response.Content.ReadAsByteArrayAsync(); var content = await response.Content.ReadAsByteArrayAsync();
AddHeaderIfDoesntExist(context, AddHeaderIfDoesntExist(context,
......
...@@ -42,7 +42,7 @@ namespace DotNetCore.CAP.Dashboard ...@@ -42,7 +42,7 @@ namespace DotNetCore.CAP.Dashboard
} }
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsync(serialized); await context.Response.WriteAsync(serialized ?? string.Empty);
} }
} }
} }
\ No newline at end of file
...@@ -124,7 +124,6 @@ namespace DotNetCore.CAP ...@@ -124,7 +124,6 @@ namespace DotNetCore.CAP
{ {
var retryBehavior = RetryBehavior.DefaultRetry; var retryBehavior = RetryBehavior.DefaultRetry;
var now = DateTime.Now;
var retries = ++message.Retries; var retries = ++message.Retries;
if (retries >= retryBehavior.RetryCount) if (retries >= retryBehavior.RetryCount)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment