Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
CAP
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tsai
CAP
Commits
27698a9a
Commit
27698a9a
authored
Sep 29, 2017
by
Savorboard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove cap.UseDashboard. It's will be automatically enabled by registerd services.
parent
778c3529
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
89 additions
and
80 deletions
+89
-80
Startup.cs
samples/Sample.RabbitMQ.PostgreSql/Startup.cs
+21
-4
Startup.cs
samples/Sample.RabbitMQ.SqlServer/Startup.cs
+1
-4
CAP.AppBuilderExtensions.cs
src/DotNetCore.CAP/CAP.AppBuilderExtensions.cs
+9
-15
CAP.DashboardMiddleware.cs
src/DotNetCore.CAP/Dashboard/CAP.DashboardMiddleware.cs
+28
-33
GatewayProxyMiddleware.cs
...Core.CAP/Dashboard/GatewayProxy/GatewayProxyMiddleware.cs
+29
-22
JsonDispatcher.cs
src/DotNetCore.CAP/Dashboard/JsonDispatcher.cs
+1
-1
IQueueExecutor.Subscibe.cs
src/DotNetCore.CAP/IQueueExecutor.Subscibe.cs
+0
-1
No files found.
samples/Sample.RabbitMQ.PostgreSql/Startup.cs
View file @
27698a9a
...
@@ -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
();
}
}
}
}
}
}
samples/Sample.RabbitMQ.SqlServer/Startup.cs
View file @
27698a9a
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
src/DotNetCore.CAP/CAP.AppBuilderExtensions.cs
View file @
27698a9a
...
@@ -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>
app
.
UseMiddleware
<
GatewayProxyMiddleware
>();
public
static
IApplicationBuilder
UseCapDashboard
(
this
IApplicationBuilder
app
)
}
{
app
.
UseMiddleware
<
DashboardMiddleware
>();
if
(
app
==
null
)
throw
new
ArgumentNullException
(
nameof
(
app
));
}
CheckRequirement
(
app
);
app
.
UseMiddleware
<
GatewayProxyMiddleware
>();
app
.
UseMiddleware
<
DashboardMiddleware
>();
return
app
;
return
app
;
}
}
...
...
src/DotNetCore.CAP/Dashboard/CAP.DashboardMiddleware.cs
View file @
27698a9a
...
@@ -25,49 +25,44 @@ namespace DotNetCore.CAP
...
@@ -25,49 +25,44 @@ 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
var
path
=
context
.
Request
.
Path
;
var
pathBase
=
context
.
Request
.
PathBase
;
context
.
Request
.
PathBase
=
pathBase
.
Add
(
matchedPath
);
context
.
Request
.
Path
=
remainingPath
;
try
{
{
// Update the path
var
dashboardContext
=
new
CapDashboardContext
(
_storage
,
_options
,
context
);
var
path
=
context
.
Request
.
Path
;
var
findResult
=
_routes
.
FindDispatcher
(
context
.
Request
.
Path
.
Value
);
var
pathBase
=
context
.
Request
.
PathBase
;
context
.
Request
.
PathBase
=
pathBase
.
Add
(
matchedPath
);
context
.
Request
.
Path
=
remainingPath
;
try
if
(
findResult
==
null
)
{
{
var
dashboardContext
=
new
CapDashboardContext
(
_storage
,
_options
,
context
);
return
_next
.
Invoke
(
context
);
var
findResult
=
_routes
.
FindDispatcher
(
context
.
Request
.
Path
.
Value
);
}
if
(
findResult
==
null
)
{
return
_next
.
Invoke
(
context
);
}
if
(
_options
.
Authorization
.
Any
(
filter
=>
!
filter
.
Authorize
(
dashboardContext
)))
if
(
_options
.
Authorization
.
Any
(
filter
=>
!
filter
.
Authorize
(
dashboardContext
)))
{
{
var
isAuthenticated
=
context
.
User
?.
Identity
?.
IsAuthenticated
;
var
isAuthenticated
=
context
.
User
?.
Identity
?.
IsAuthenticated
;
context
.
Response
.
StatusCode
=
isAuthenticated
==
true
context
.
Response
.
StatusCode
=
isAuthenticated
==
true
?
(
int
)
HttpStatusCode
.
Forbidden
?
(
int
)
HttpStatusCode
.
Forbidden
:
(
int
)
HttpStatusCode
.
Unauthorized
;
:
(
int
)
HttpStatusCode
.
Unauthorized
;
return
Task
.
CompletedTask
;
return
Task
.
CompletedTask
;
}
}
dashboardContext
.
UriMatch
=
findResult
.
Item2
;
dashboardContext
.
UriMatch
=
findResult
.
Item2
;
return
findResult
.
Item1
.
Dispatch
(
dashboardContext
);
return
findResult
.
Item1
.
Dispatch
(
dashboardContext
);
}
finally
{
context
.
Request
.
PathBase
=
pathBase
;
context
.
Request
.
Path
=
path
;
}
}
}
else
finally
{
{
return
_next
(
context
);
context
.
Request
.
PathBase
=
pathBase
;
context
.
Request
.
Path
=
path
;
}
}
}
}
}
}
...
...
src/DotNetCore.CAP/Dashboard/GatewayProxy/GatewayProxyMiddleware.cs
View file @
27698a9a
...
@@ -46,40 +46,48 @@ namespace DotNetCore.CAP.Dashboard.GatewayProxy
...
@@ -46,40 +46,48 @@ 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
)
var
isSwitchNode
=
request
.
Cookies
.
TryGetValue
(
NodeCookieName
,
out
string
requestNodeId
);
var
isCurrentNode
=
discoveryOptions
.
NodeId
.
ToString
()
==
requestNodeId
;
if
(!
isCapRequest
||
!
isSwitchNode
||
isCurrentNode
)
{
{
await
_next
.
Invoke
(
context
);
await
_next
.
Invoke
(
context
);
}
}
else
else
{
{
_logger
.
LogDebug
(
"started calling gateway proxy middleware"
);
//For performance reasons, we need to put this functionality in the else
var
isSwitchNode
=
request
.
Cookies
.
TryGetValue
(
NodeCookieName
,
out
string
requestNodeId
);
var
isCurrentNode
=
discoveryOptions
.
NodeId
.
ToString
()
==
requestNodeId
;
var
isNodesPage
=
request
.
Path
.
StartsWithSegments
(
new
PathString
(
pathMatch
+
"/nodes"
));
if
(
TryGetRemoteNode
(
requestNodeId
,
out
Node
node
))
if
(!
isSwitchNode
||
isCurrentNode
||
isNodesPage
)
{
await
_next
.
Invoke
(
context
);
}
else
{
{
try
_logger
.
LogDebug
(
"started calling gateway proxy middleware"
);
if
(
TryGetRemoteNode
(
requestNodeId
,
out
Node
node
))
{
{
DownstreamRequest
=
await
_requestMapper
.
Map
(
request
);
try
{
DownstreamRequest
=
await
_requestMapper
.
Map
(
request
);
SetDownStreamRequestUri
(
node
,
request
.
Path
.
Value
);
SetDownStreamRequestUri
(
node
,
request
.
Path
.
Value
);
var
response
=
await
_requester
.
GetResponse
(
DownstreamRequest
);
var
response
=
await
_requester
.
GetResponse
(
DownstreamRequest
);
await
SetResponseOnHttpContext
(
context
,
response
);
await
SetResponseOnHttpContext
(
context
,
response
);
}
catch
(
Exception
ex
)
{
_logger
.
LogError
(
ex
.
Message
);
}
}
}
catch
(
Exception
ex
)
else
{
{
_logger
.
LogError
(
ex
.
Message
);
context
.
Response
.
Cookies
.
Delete
(
NodeCookieName
);
await
_next
.
Invoke
(
context
);
}
}
}
}
else
{
context
.
Response
.
Cookies
.
Delete
(
NodeCookieName
);
await
_next
.
Invoke
(
context
);
}
}
}
}
}
...
@@ -90,10 +98,9 @@ namespace DotNetCore.CAP.Dashboard.GatewayProxy
...
@@ -90,10 +98,9 @@ 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
,
new
KeyValuePair
<
string
,
IEnumerable
<
string
>>(
"Content-Length"
,
new
[]
{
content
.
Length
.
ToString
()
}));
new
KeyValuePair
<
string
,
IEnumerable
<
string
>>(
"Content-Length"
,
new
[]
{
content
.
Length
.
ToString
()
}));
context
.
Response
.
OnStarting
(
state
=>
context
.
Response
.
OnStarting
(
state
=>
...
@@ -128,7 +135,7 @@ namespace DotNetCore.CAP.Dashboard.GatewayProxy
...
@@ -128,7 +135,7 @@ namespace DotNetCore.CAP.Dashboard.GatewayProxy
DownstreamRequest
.
RequestUri
=
uriBuilder
.
Uri
;
DownstreamRequest
.
RequestUri
=
uriBuilder
.
Uri
;
}
}
private
static
void
AddHeaderIfDoesntExist
(
HttpContext
context
,
private
static
void
AddHeaderIfDoesntExist
(
HttpContext
context
,
KeyValuePair
<
string
,
IEnumerable
<
string
>>
httpResponseHeader
)
KeyValuePair
<
string
,
IEnumerable
<
string
>>
httpResponseHeader
)
{
{
if
(!
context
.
Response
.
Headers
.
ContainsKey
(
httpResponseHeader
.
Key
))
if
(!
context
.
Response
.
Headers
.
ContainsKey
(
httpResponseHeader
.
Key
))
...
...
src/DotNetCore.CAP/Dashboard/JsonDispatcher.cs
View file @
27698a9a
...
@@ -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
src/DotNetCore.CAP/IQueueExecutor.Subscibe.cs
View file @
27698a9a
...
@@ -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
)
{
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment