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
d0d8b40d
Commit
d0d8b40d
authored
Sep 16, 2017
by
Savorboard
Committed by
GitHub
Sep 16, 2017
Browse files
Options
Browse Files
Download
Plain Diff
release 2.0.1
release 2.0.1
parents
4fb1e080
e7d99983
Changes
19
Show whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
121 additions
and
102 deletions
+121
-102
.gitignore
.gitignore
+4
-0
version.props
build/version.props
+1
-1
Program.cs
samples/Sample.RabbitMQ.SqlServer/Program.cs
+20
-11
CAP.KafkaCapOptionsExtension.cs
src/DotNetCore.CAP.Kafka/CAP.KafkaCapOptionsExtension.cs
+1
-1
CAP.RabbitMQCapOptionsExtension.cs
...otNetCore.CAP.RabbitMQ/CAP.RabbitMQCapOptionsExtension.cs
+1
-2
ConnectionPool.cs
src/DotNetCore.CAP.RabbitMQ/ConnectionPool.cs
+1
-1
PublishQueueExecutor.cs
src/DotNetCore.CAP.RabbitMQ/PublishQueueExecutor.cs
+10
-4
RabbitMQConsumerClient.cs
src/DotNetCore.CAP.RabbitMQ/RabbitMQConsumerClient.cs
+8
-5
RabbitMQConsumerClientFactory.cs
src/DotNetCore.CAP.RabbitMQ/RabbitMQConsumerClientFactory.cs
+4
-4
CAP.SqlServerCapOptionsExtension.cs
...NetCore.CAP.SqlServer/CAP.SqlServerCapOptionsExtension.cs
+13
-5
IConsumerServiceSelector.cs
src/DotNetCore.CAP/Abstractions/IConsumerServiceSelector.cs
+2
-3
CAP.ServiceCollectionExtensions.cs
src/DotNetCore.CAP/CAP.ServiceCollectionExtensions.cs
+0
-9
IBootstrapper.Default.cs
src/DotNetCore.CAP/IBootstrapper.Default.cs
+2
-5
IConsumerHandler.Default.cs
src/DotNetCore.CAP/IConsumerHandler.Default.cs
+1
-1
ConsumerInvokerFactory.cs
src/DotNetCore.CAP/Internal/ConsumerInvokerFactory.cs
+5
-8
IConsumerInvoker.Default.cs
src/DotNetCore.CAP/Internal/IConsumerInvoker.Default.cs
+20
-16
IConsumerServiceSelector.Default.cs
...tNetCore.CAP/Internal/IConsumerServiceSelector.Default.cs
+24
-21
MethodMatcherCache.cs
src/DotNetCore.CAP/Internal/MethodMatcherCache.cs
+2
-3
ConsumerServiceSelectorTest.cs
test/DotNetCore.CAP.Test/ConsumerServiceSelectorTest.cs
+2
-2
No files found.
.gitignore
View file @
d0d8b40d
...
@@ -35,3 +35,7 @@ bin/
...
@@ -35,3 +35,7 @@ bin/
/.idea
/.idea
Properties
Properties
/pack.bat
/pack.bat
/src/DotNetCore.CAP/project.json
/src/DotNetCore.CAP/packages.config
/src/DotNetCore.CAP/DotNetCore.CAP.Net47.csproj
/NuGet.config
build/version.props
View file @
d0d8b40d
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
<PropertyGroup>
<PropertyGroup>
<VersionMajor>2</VersionMajor>
<VersionMajor>2</VersionMajor>
<VersionMinor>0</VersionMinor>
<VersionMinor>0</VersionMinor>
<VersionPatch>
0
</VersionPatch>
<VersionPatch>
1
</VersionPatch>
<VersionQuality></VersionQuality>
<VersionQuality></VersionQuality>
<VersionPrefix>$(VersionMajor).$(VersionMinor).$(VersionPatch)</VersionPrefix>
<VersionPrefix>$(VersionMajor).$(VersionMinor).$(VersionPatch)</VersionPrefix>
</PropertyGroup>
</PropertyGroup>
...
...
samples/Sample.RabbitMQ.SqlServer/Program.cs
View file @
d0d8b40d
using
System.IO
;
using
System.IO
;
using
Microsoft.AspNetCore
;
using
Microsoft.AspNetCore.Builder
;
using
Microsoft.AspNetCore.Builder
;
using
Microsoft.AspNetCore.Hosting
;
using
Microsoft.AspNetCore.Hosting
;
using
Microsoft.Extensions.Configuration
;
using
Microsoft.Extensions.Configuration
;
...
@@ -7,22 +8,30 @@ namespace Sample.RabbitMQ.SqlServer
...
@@ -7,22 +8,30 @@ namespace Sample.RabbitMQ.SqlServer
{
{
public
class
Program
public
class
Program
{
{
//var config = new ConfigurationBuilder()
// .AddCommandLine(args)
// .AddEnvironmentVariables("ASPNETCORE_")
// .Build();
//var host = new WebHostBuilder()
// .UseConfiguration(config)
// .UseKestrel()
// .UseContentRoot(Directory.GetCurrentDirectory())
// .UseIISIntegration()
// .UseStartup<Startup>()
// .Build();
//host.Run();
public
static
void
Main
(
string
[]
args
)
public
static
void
Main
(
string
[]
args
)
{
{
var
config
=
new
ConfigurationBuilder
()
BuildWebHost
(
args
).
Run
();
.
AddCommandLine
(
args
)
}
.
AddEnvironmentVariables
(
"ASPNETCORE_"
)
.
Build
();
var
host
=
new
WebHostBuilder
()
public
static
IWebHost
BuildWebHost
(
string
[]
args
)
=>
.
UseConfiguration
(
config
)
WebHost
.
CreateDefaultBuilder
(
args
)
.
UseKestrel
()
.
UseContentRoot
(
Directory
.
GetCurrentDirectory
())
.
UseIISIntegration
()
.
UseStartup
<
Startup
>()
.
UseStartup
<
Startup
>()
.
Build
();
.
Build
();
host
.
Run
();
}
}
}
}
}
\ No newline at end of file
src/DotNetCore.CAP.Kafka/CAP.KafkaCapOptionsExtension.cs
View file @
d0d8b40d
...
@@ -21,7 +21,7 @@ namespace DotNetCore.CAP
...
@@ -21,7 +21,7 @@ namespace DotNetCore.CAP
services
.
AddSingleton
(
kafkaOptions
);
services
.
AddSingleton
(
kafkaOptions
);
services
.
AddSingleton
<
IConsumerClientFactory
,
KafkaConsumerClientFactory
>();
services
.
AddSingleton
<
IConsumerClientFactory
,
KafkaConsumerClientFactory
>();
services
.
Add
Transient
<
IQueueExecutor
,
PublishQueueExecutor
>();
services
.
Add
Singleton
<
IQueueExecutor
,
PublishQueueExecutor
>();
}
}
}
}
}
}
\ No newline at end of file
src/DotNetCore.CAP.RabbitMQ/CAP.RabbitMQCapOptionsExtension.cs
View file @
d0d8b40d
...
@@ -23,9 +23,8 @@ namespace DotNetCore.CAP
...
@@ -23,9 +23,8 @@ namespace DotNetCore.CAP
services
.
AddSingleton
<
IConsumerClientFactory
,
RabbitMQConsumerClientFactory
>();
services
.
AddSingleton
<
IConsumerClientFactory
,
RabbitMQConsumerClientFactory
>();
services
.
AddSingleton
<
ConnectionPool
>();
services
.
AddSingleton
<
ConnectionPool
>();
services
.
AddScoped
(
x
=>
x
.
GetService
<
ConnectionPool
>().
Rent
());
services
.
Add
Transient
<
IQueueExecutor
,
PublishQueueExecutor
>();
services
.
Add
Singleton
<
IQueueExecutor
,
PublishQueueExecutor
>();
}
}
}
}
}
}
\ No newline at end of file
src/DotNetCore.CAP.RabbitMQ/ConnectionPool.cs
View file @
d0d8b40d
...
@@ -8,7 +8,7 @@ namespace DotNetCore.CAP.RabbitMQ
...
@@ -8,7 +8,7 @@ namespace DotNetCore.CAP.RabbitMQ
{
{
public
class
ConnectionPool
:
IConnectionPool
,
IDisposable
public
class
ConnectionPool
:
IConnectionPool
,
IDisposable
{
{
private
const
int
DefaultPoolSize
=
32
;
private
const
int
DefaultPoolSize
=
15
;
private
readonly
ConcurrentQueue
<
IConnection
>
_pool
=
new
ConcurrentQueue
<
IConnection
>();
private
readonly
ConcurrentQueue
<
IConnection
>
_pool
=
new
ConcurrentQueue
<
IConnection
>();
...
...
src/DotNetCore.CAP.RabbitMQ/PublishQueueExecutor.cs
View file @
d0d8b40d
...
@@ -10,27 +10,29 @@ namespace DotNetCore.CAP.RabbitMQ
...
@@ -10,27 +10,29 @@ namespace DotNetCore.CAP.RabbitMQ
internal
sealed
class
PublishQueueExecutor
:
BasePublishQueueExecutor
internal
sealed
class
PublishQueueExecutor
:
BasePublishQueueExecutor
{
{
private
readonly
ILogger
_logger
;
private
readonly
ILogger
_logger
;
private
readonly
IConnection
_connection
;
private
readonly
ConnectionPool
_connectionPool
;
private
readonly
RabbitMQOptions
_rabbitMQOptions
;
private
readonly
RabbitMQOptions
_rabbitMQOptions
;
public
PublishQueueExecutor
(
public
PublishQueueExecutor
(
CapOptions
options
,
CapOptions
options
,
IStateChanger
stateChanger
,
IStateChanger
stateChanger
,
IConnection
connection
,
ConnectionPool
connectionPool
,
RabbitMQOptions
rabbitMQOptions
,
RabbitMQOptions
rabbitMQOptions
,
ILogger
<
PublishQueueExecutor
>
logger
)
ILogger
<
PublishQueueExecutor
>
logger
)
:
base
(
options
,
stateChanger
,
logger
)
:
base
(
options
,
stateChanger
,
logger
)
{
{
_logger
=
logger
;
_logger
=
logger
;
_connection
=
connection
;
_connection
Pool
=
connectionPool
;
_rabbitMQOptions
=
rabbitMQOptions
;
_rabbitMQOptions
=
rabbitMQOptions
;
}
}
public
override
Task
<
OperateResult
>
PublishAsync
(
string
keyName
,
string
content
)
public
override
Task
<
OperateResult
>
PublishAsync
(
string
keyName
,
string
content
)
{
{
var
connection
=
_connectionPool
.
Rent
();
try
try
{
{
using
(
var
channel
=
_
connection
.
CreateModel
())
using
(
var
channel
=
connection
.
CreateModel
())
{
{
var
body
=
Encoding
.
UTF8
.
GetBytes
(
content
);
var
body
=
Encoding
.
UTF8
.
GetBytes
(
content
);
...
@@ -55,6 +57,10 @@ namespace DotNetCore.CAP.RabbitMQ
...
@@ -55,6 +57,10 @@ namespace DotNetCore.CAP.RabbitMQ
Description
=
ex
.
Message
Description
=
ex
.
Message
}));
}));
}
}
finally
{
_connectionPool
.
Return
(
connection
);
}
}
}
}
}
}
}
\ No newline at end of file
src/DotNetCore.CAP.RabbitMQ/RabbitMQConsumerClient.cs
View file @
d0d8b40d
...
@@ -14,7 +14,7 @@ namespace DotNetCore.CAP.RabbitMQ
...
@@ -14,7 +14,7 @@ namespace DotNetCore.CAP.RabbitMQ
private
readonly
string
_queueName
;
private
readonly
string
_queueName
;
private
readonly
RabbitMQOptions
_rabbitMQOptions
;
private
readonly
RabbitMQOptions
_rabbitMQOptions
;
private
IConnection
_connection
;
private
ConnectionPool
_connectionPool
;
private
IModel
_channel
;
private
IModel
_channel
;
private
ulong
_deliveryTag
;
private
ulong
_deliveryTag
;
...
@@ -23,11 +23,11 @@ namespace DotNetCore.CAP.RabbitMQ
...
@@ -23,11 +23,11 @@ namespace DotNetCore.CAP.RabbitMQ
public
event
EventHandler
<
string
>
OnError
;
public
event
EventHandler
<
string
>
OnError
;
public
RabbitMQConsumerClient
(
string
queueName
,
public
RabbitMQConsumerClient
(
string
queueName
,
IConnection
connection
,
ConnectionPool
connectionPool
,
RabbitMQOptions
options
)
RabbitMQOptions
options
)
{
{
_queueName
=
queueName
;
_queueName
=
queueName
;
_connection
=
connection
;
_connection
Pool
=
connectionPool
;
_rabbitMQOptions
=
options
;
_rabbitMQOptions
=
options
;
_exchageName
=
options
.
TopicExchangeName
;
_exchageName
=
options
.
TopicExchangeName
;
...
@@ -36,7 +36,9 @@ namespace DotNetCore.CAP.RabbitMQ
...
@@ -36,7 +36,9 @@ namespace DotNetCore.CAP.RabbitMQ
private
void
InitClient
()
private
void
InitClient
()
{
{
_channel
=
_connection
.
CreateModel
();
var
connection
=
_connectionPool
.
Rent
();
_channel
=
connection
.
CreateModel
();
_channel
.
ExchangeDeclare
(
_channel
.
ExchangeDeclare
(
exchange
:
_exchageName
,
exchange
:
_exchageName
,
...
@@ -49,6 +51,8 @@ namespace DotNetCore.CAP.RabbitMQ
...
@@ -49,6 +51,8 @@ namespace DotNetCore.CAP.RabbitMQ
exclusive
:
false
,
exclusive
:
false
,
autoDelete
:
false
,
autoDelete
:
false
,
arguments
:
arguments
);
arguments
:
arguments
);
_connectionPool
.
Return
(
connection
);
}
}
public
void
Subscribe
(
IEnumerable
<
string
>
topics
)
public
void
Subscribe
(
IEnumerable
<
string
>
topics
)
...
@@ -81,7 +85,6 @@ namespace DotNetCore.CAP.RabbitMQ
...
@@ -81,7 +85,6 @@ namespace DotNetCore.CAP.RabbitMQ
public
void
Dispose
()
public
void
Dispose
()
{
{
_channel
.
Dispose
();
_channel
.
Dispose
();
_connection
.
Dispose
();
}
}
private
void
OnConsumerReceived
(
object
sender
,
BasicDeliverEventArgs
e
)
private
void
OnConsumerReceived
(
object
sender
,
BasicDeliverEventArgs
e
)
...
...
src/DotNetCore.CAP.RabbitMQ/RabbitMQConsumerClientFactory.cs
View file @
d0d8b40d
...
@@ -6,18 +6,18 @@ namespace DotNetCore.CAP.RabbitMQ
...
@@ -6,18 +6,18 @@ namespace DotNetCore.CAP.RabbitMQ
internal
sealed
class
RabbitMQConsumerClientFactory
:
IConsumerClientFactory
internal
sealed
class
RabbitMQConsumerClientFactory
:
IConsumerClientFactory
{
{
private
readonly
RabbitMQOptions
_rabbitMQOptions
;
private
readonly
RabbitMQOptions
_rabbitMQOptions
;
private
readonly
IConnection
_connection
;
private
readonly
ConnectionPool
_connectionPool
;
public
RabbitMQConsumerClientFactory
(
RabbitMQOptions
rabbitMQOptions
,
IConnection
connection
)
public
RabbitMQConsumerClientFactory
(
RabbitMQOptions
rabbitMQOptions
,
ConnectionPool
pool
)
{
{
_rabbitMQOptions
=
rabbitMQOptions
;
_rabbitMQOptions
=
rabbitMQOptions
;
_connection
=
connection
;
_connection
Pool
=
pool
;
}
}
public
IConsumerClient
Create
(
string
groupId
)
public
IConsumerClient
Create
(
string
groupId
)
{
{
return
new
RabbitMQConsumerClient
(
groupId
,
_connection
,
_rabbitMQOptions
);
return
new
RabbitMQConsumerClient
(
groupId
,
_connection
Pool
,
_rabbitMQOptions
);
}
}
}
}
}
}
\ No newline at end of file
src/DotNetCore.CAP.SqlServer/CAP.SqlServerCapOptionsExtension.cs
View file @
d0d8b40d
...
@@ -19,11 +19,15 @@ namespace DotNetCore.CAP
...
@@ -19,11 +19,15 @@ namespace DotNetCore.CAP
public
void
AddServices
(
IServiceCollection
services
)
public
void
AddServices
(
IServiceCollection
services
)
{
{
services
.
AddSingleton
<
IStorage
,
SqlServerStorage
>();
services
.
AddSingleton
<
IStorage
,
SqlServerStorage
>();
services
.
AddS
coped
<
IStorageConnection
,
SqlServerStorageConnection
>();
services
.
AddS
ingleton
<
IStorageConnection
,
SqlServerStorageConnection
>();
services
.
Add
Scoped
<
ICapPublisher
,
CapPublisher
>();
services
.
Add
Transient
<
ICapPublisher
,
CapPublisher
>();
services
.
AddTransient
<
ICallbackPublisher
,
CapPublisher
>();
services
.
AddTransient
<
ICallbackPublisher
,
CapPublisher
>();
services
.
AddTransient
<
IAdditionalProcessor
,
DefaultAdditionalProcessor
>();
services
.
AddTransient
<
IAdditionalProcessor
,
DefaultAdditionalProcessor
>();
AddSqlServerOptions
(
services
);
}
private
void
AddSqlServerOptions
(
IServiceCollection
services
)
{
var
sqlServerOptions
=
new
SqlServerOptions
();
var
sqlServerOptions
=
new
SqlServerOptions
();
_configure
(
sqlServerOptions
);
_configure
(
sqlServerOptions
);
...
@@ -32,9 +36,13 @@ namespace DotNetCore.CAP
...
@@ -32,9 +36,13 @@ namespace DotNetCore.CAP
{
{
services
.
AddSingleton
(
x
=>
services
.
AddSingleton
(
x
=>
{
{
var
dbContext
=
(
DbContext
)
x
.
GetService
(
sqlServerOptions
.
DbContextType
);
using
(
var
scope
=
x
.
CreateScope
())
{
var
provider
=
scope
.
ServiceProvider
;
var
dbContext
=
(
DbContext
)
provider
.
GetService
(
sqlServerOptions
.
DbContextType
);
sqlServerOptions
.
ConnectionString
=
dbContext
.
Database
.
GetDbConnection
().
ConnectionString
;
sqlServerOptions
.
ConnectionString
=
dbContext
.
Database
.
GetDbConnection
().
ConnectionString
;
return
sqlServerOptions
;
return
sqlServerOptions
;
}
});
});
}
}
else
else
...
...
src/DotNetCore.CAP/Abstractions/IConsumerServiceSelector.cs
View file @
d0d8b40d
...
@@ -12,9 +12,8 @@ namespace DotNetCore.CAP.Abstractions
...
@@ -12,9 +12,8 @@ namespace DotNetCore.CAP.Abstractions
/// Selects a set of <see cref="ConsumerExecutorDescriptor"/> candidates for the current message associated with
/// Selects a set of <see cref="ConsumerExecutorDescriptor"/> candidates for the current message associated with
/// <paramref name="provider"/>.
/// <paramref name="provider"/>.
/// </summary>
/// </summary>
/// <param name="provider"> <see cref="IServiceProvider"/>.</param>
/// <returns>A set of <see cref="ConsumerExecutorDescriptor"/> candidates or <c>null</c>.</returns>
/// <returns>A set of <see cref="ConsumerExecutorDescriptor"/> candidates or <c>null</c>.</returns>
IReadOnlyList
<
ConsumerExecutorDescriptor
>
SelectCandidates
(
IServiceProvider
provider
);
IReadOnlyList
<
ConsumerExecutorDescriptor
>
SelectCandidates
();
/// <summary>
/// <summary>
/// Selects the best <see cref="ConsumerExecutorDescriptor"/> candidate from <paramref name="candidates"/> for the
/// Selects the best <see cref="ConsumerExecutorDescriptor"/> candidate from <paramref name="candidates"/> for the
...
...
src/DotNetCore.CAP/CAP.ServiceCollectionExtensions.cs
View file @
d0d8b40d
...
@@ -82,15 +82,6 @@ namespace Microsoft.Extensions.DependencyInjection
...
@@ -82,15 +82,6 @@ namespace Microsoft.Extensions.DependencyInjection
{
{
services
.
AddTransient
(
service
.
Key
,
service
.
Value
);
services
.
AddTransient
(
service
.
Key
,
service
.
Value
);
}
}
var
types
=
Assembly
.
GetEntryAssembly
().
ExportedTypes
;
foreach
(
var
type
in
types
)
{
if
(
Helper
.
IsController
(
type
.
GetTypeInfo
()))
{
services
.
AddTransient
(
typeof
(
object
),
type
);
}
}
}
}
}
}
}
}
\ No newline at end of file
src/DotNetCore.CAP/IBootstrapper.Default.cs
View file @
d0d8b40d
...
@@ -25,14 +25,13 @@ namespace DotNetCore.CAP
...
@@ -25,14 +25,13 @@ namespace DotNetCore.CAP
IOptions
<
CapOptions
>
options
,
IOptions
<
CapOptions
>
options
,
IStorage
storage
,
IStorage
storage
,
IApplicationLifetime
appLifetime
,
IApplicationLifetime
appLifetime
,
I
ServiceProvider
provider
)
I
Enumerable
<
IProcessingServer
>
servers
)
{
{
_logger
=
logger
;
_logger
=
logger
;
_appLifetime
=
appLifetime
;
_appLifetime
=
appLifetime
;
Options
=
options
.
Value
;
Options
=
options
.
Value
;
Storage
=
storage
;
Storage
=
storage
;
Provider
=
provider
;
Servers
=
servers
;
Servers
=
Provider
.
GetServices
<
IProcessingServer
>();
_cts
=
new
CancellationTokenSource
();
_cts
=
new
CancellationTokenSource
();
_ctsRegistration
=
appLifetime
.
ApplicationStopping
.
Register
(()
=>
_ctsRegistration
=
appLifetime
.
ApplicationStopping
.
Register
(()
=>
...
@@ -55,8 +54,6 @@ namespace DotNetCore.CAP
...
@@ -55,8 +54,6 @@ namespace DotNetCore.CAP
protected
IEnumerable
<
IProcessingServer
>
Servers
{
get
;
}
protected
IEnumerable
<
IProcessingServer
>
Servers
{
get
;
}
public
IServiceProvider
Provider
{
get
;
private
set
;
}
public
Task
BootstrapAsync
()
public
Task
BootstrapAsync
()
{
{
return
(
_bootstrappingTask
=
BootstrapTaskAsync
());
return
(
_bootstrappingTask
=
BootstrapTaskAsync
());
...
...
src/DotNetCore.CAP/IConsumerHandler.Default.cs
View file @
d0d8b40d
...
@@ -47,7 +47,7 @@ namespace DotNetCore.CAP
...
@@ -47,7 +47,7 @@ namespace DotNetCore.CAP
public
void
Start
()
public
void
Start
()
{
{
var
groupingMatchs
=
_selector
.
GetCandidatesMethodsOfGroupNameGrouped
(
_serviceProvider
);
var
groupingMatchs
=
_selector
.
GetCandidatesMethodsOfGroupNameGrouped
();
foreach
(
var
matchGroup
in
groupingMatchs
)
foreach
(
var
matchGroup
in
groupingMatchs
)
{
{
...
...
src/DotNetCore.CAP/Internal/ConsumerInvokerFactory.cs
View file @
d0d8b40d
using
System
;
using
System
;
using
DotNetCore.CAP.Abstractions
;
using
DotNetCore.CAP.Abstractions
;
using
Microsoft.Extensions.DependencyInjection
;
using
Microsoft.Extensions.Logging
;
using
Microsoft.Extensions.Logging
;
namespace
DotNetCore.CAP.Internal
namespace
DotNetCore.CAP.Internal
...
@@ -22,16 +21,14 @@ namespace DotNetCore.CAP.Internal
...
@@ -22,16 +21,14 @@ namespace DotNetCore.CAP.Internal
}
}
public
IConsumerInvoker
CreateInvoker
(
ConsumerContext
consumerContext
)
public
IConsumerInvoker
CreateInvoker
(
ConsumerContext
consumerContext
)
{
using
(
var
scope
=
_serviceProvider
.
CreateScope
())
{
{
var
context
=
new
ConsumerInvokerContext
(
consumerContext
)
var
context
=
new
ConsumerInvokerContext
(
consumerContext
)
{
{
Result
=
new
DefaultConsumerInvoker
(
_logger
,
scope
.
ServiceProvider
,
_modelBinderFactory
,
consumerContext
)
Result
=
new
DefaultConsumerInvoker
(
_logger
,
_serviceProvider
,
_modelBinderFactory
,
consumerContext
)
};
};
return
context
.
Result
;
return
context
.
Result
;
}
}
}
}
}
}
}
\ No newline at end of file
src/DotNetCore.CAP/Internal/IConsumerInvoker.Default.cs
View file @
d0d8b40d
...
@@ -35,8 +35,11 @@ namespace DotNetCore.CAP.Internal
...
@@ -35,8 +35,11 @@ namespace DotNetCore.CAP.Internal
{
{
_logger
.
LogDebug
(
"Executing consumer Topic: {0}"
,
_consumerContext
.
ConsumerDescriptor
.
MethodInfo
.
Name
);
_logger
.
LogDebug
(
"Executing consumer Topic: {0}"
,
_consumerContext
.
ConsumerDescriptor
.
MethodInfo
.
Name
);
var
obj
=
ActivatorUtilities
.
GetServiceOrCreateInstance
(
_serviceProvider
,
using
(
var
scope
=
_serviceProvider
.
CreateScope
())
_consumerContext
.
ConsumerDescriptor
.
ImplTypeInfo
.
AsType
());
{
var
provider
=
scope
.
ServiceProvider
;
var
serviceType
=
_consumerContext
.
ConsumerDescriptor
.
ImplTypeInfo
.
AsType
();
var
obj
=
ActivatorUtilities
.
GetServiceOrCreateInstance
(
provider
,
serviceType
);
var
jsonConent
=
_consumerContext
.
DeliverMessage
.
Content
;
var
jsonConent
=
_consumerContext
.
DeliverMessage
.
Content
;
var
message
=
Helper
.
FromJson
<
Message
>(
jsonConent
);
var
message
=
Helper
.
FromJson
<
Message
>(
jsonConent
);
...
@@ -56,6 +59,7 @@ namespace DotNetCore.CAP.Internal
...
@@ -56,6 +59,7 @@ namespace DotNetCore.CAP.Internal
await
SentCallbackMessage
(
message
.
Id
,
message
.
CallbackName
,
result
);
await
SentCallbackMessage
(
message
.
Id
,
message
.
CallbackName
,
result
);
}
}
}
}
}
private
async
Task
<
object
>
ExecuteAsync
(
object
@class
)
private
async
Task
<
object
>
ExecuteAsync
(
object
@class
)
{
{
...
...
src/DotNetCore.CAP/Internal/IConsumerServiceSelector.Default.cs
View file @
d0d8b40d
...
@@ -33,13 +33,13 @@ namespace DotNetCore.CAP.Internal
...
@@ -33,13 +33,13 @@ namespace DotNetCore.CAP.Internal
return
executeDescriptor
.
FirstOrDefault
(
x
=>
x
.
Attribute
.
Name
==
key
);
return
executeDescriptor
.
FirstOrDefault
(
x
=>
x
.
Attribute
.
Name
==
key
);
}
}
public
IReadOnlyList
<
ConsumerExecutorDescriptor
>
SelectCandidates
(
IServiceProvider
provider
)
public
IReadOnlyList
<
ConsumerExecutorDescriptor
>
SelectCandidates
()
{
{
var
executorDescriptorList
=
new
List
<
ConsumerExecutorDescriptor
>();
var
executorDescriptorList
=
new
List
<
ConsumerExecutorDescriptor
>();
executorDescriptorList
.
AddRange
(
FindConsumersFromInterfaceTypes
(
p
rovider
));
executorDescriptorList
.
AddRange
(
FindConsumersFromInterfaceTypes
(
_serviceP
rovider
));
executorDescriptorList
.
AddRange
(
FindConsumersFromControllerTypes
(
p
rovider
));
executorDescriptorList
.
AddRange
(
FindConsumersFromControllerTypes
(
_serviceP
rovider
));
return
executorDescriptorList
;
return
executorDescriptorList
;
}
}
...
@@ -49,7 +49,10 @@ namespace DotNetCore.CAP.Internal
...
@@ -49,7 +49,10 @@ namespace DotNetCore.CAP.Internal
{
{
var
executorDescriptorList
=
new
List
<
ConsumerExecutorDescriptor
>();
var
executorDescriptorList
=
new
List
<
ConsumerExecutorDescriptor
>();
var
consumerServices
=
provider
.
GetServices
<
ICapSubscribe
>();
using
(
var
scoped
=
provider
.
CreateScope
())
{
var
scopedProvider
=
scoped
.
ServiceProvider
;
var
consumerServices
=
scopedProvider
.
GetServices
<
ICapSubscribe
>();
foreach
(
var
service
in
consumerServices
)
foreach
(
var
service
in
consumerServices
)
{
{
var
typeInfo
=
service
.
GetType
().
GetTypeInfo
();
var
typeInfo
=
service
.
GetType
().
GetTypeInfo
();
...
@@ -62,22 +65,22 @@ namespace DotNetCore.CAP.Internal
...
@@ -62,22 +65,22 @@ namespace DotNetCore.CAP.Internal
}
}
return
executorDescriptorList
;
return
executorDescriptorList
;
}
}
}
private
static
IEnumerable
<
ConsumerExecutorDescriptor
>
FindConsumersFromControllerTypes
(
private
static
IEnumerable
<
ConsumerExecutorDescriptor
>
FindConsumersFromControllerTypes
(
IServiceProvider
provider
)
IServiceProvider
provider
)
{
{
var
executorDescriptorList
=
new
List
<
ConsumerExecutorDescriptor
>();
var
executorDescriptorList
=
new
List
<
ConsumerExecutorDescriptor
>();
// at cap startup time, find all Controller into the DI container,the type is object.
var
controllers
=
provider
.
GetServices
<
object
>();
foreach
(
var
controller
in
controllers
)
{
var
typeInfo
=
controller
.
GetType
().
GetTypeInfo
();
//double check
if
(!
Helper
.
IsController
(
typeInfo
))
continue
;
var
types
=
Assembly
.
GetEntryAssembly
().
ExportedTypes
;
foreach
(
var
type
in
types
)
{
var
typeInfo
=
type
.
GetTypeInfo
();
if
(
Helper
.
IsController
(
typeInfo
))
{
executorDescriptorList
.
AddRange
(
GetTopicAttributesDescription
(
typeInfo
));
executorDescriptorList
.
AddRange
(
GetTopicAttributesDescription
(
typeInfo
));
}
}
}
return
executorDescriptorList
;
return
executorDescriptorList
;
}
}
...
...
src/DotNetCore.CAP/Internal/MethodMatcherCache.cs
View file @
d0d8b40d
...
@@ -22,12 +22,11 @@ namespace DotNetCore.CAP.Internal
...
@@ -22,12 +22,11 @@ namespace DotNetCore.CAP.Internal
/// Get a dictionary of candidates.In the dictionary,
/// Get a dictionary of candidates.In the dictionary,
/// the Key is the CAPSubscribeAttribute Group, the Value for the current Group of candidates
/// the Key is the CAPSubscribeAttribute Group, the Value for the current Group of candidates
/// </summary>
/// </summary>
/// <param name="provider"><see cref="IServiceProvider"/></param>
public
ConcurrentDictionary
<
string
,
IList
<
ConsumerExecutorDescriptor
>>
GetCandidatesMethodsOfGroupNameGrouped
()
public
ConcurrentDictionary
<
string
,
IList
<
ConsumerExecutorDescriptor
>>
GetCandidatesMethodsOfGroupNameGrouped
(
IServiceProvider
provider
)
{
{
if
(
Entries
.
Count
!=
0
)
return
Entries
;
if
(
Entries
.
Count
!=
0
)
return
Entries
;
var
executorCollection
=
_selector
.
SelectCandidates
(
provider
);
var
executorCollection
=
_selector
.
SelectCandidates
();
var
groupedCandidates
=
executorCollection
.
GroupBy
(
x
=>
x
.
Attribute
.
Group
);
var
groupedCandidates
=
executorCollection
.
GroupBy
(
x
=>
x
.
Attribute
.
Group
);
...
...
test/DotNetCore.CAP.Test/ConsumerServiceSelectorTest.cs
View file @
d0d8b40d
...
@@ -25,7 +25,7 @@ namespace DotNetCore.CAP.Test
...
@@ -25,7 +25,7 @@ namespace DotNetCore.CAP.Test
public
void
CanFindAllConsumerService
()
public
void
CanFindAllConsumerService
()
{
{
var
selector
=
_provider
.
GetRequiredService
<
IConsumerServiceSelector
>();
var
selector
=
_provider
.
GetRequiredService
<
IConsumerServiceSelector
>();
var
candidates
=
selector
.
SelectCandidates
(
_provider
);
var
candidates
=
selector
.
SelectCandidates
();
Assert
.
Equal
(
2
,
candidates
.
Count
);
Assert
.
Equal
(
2
,
candidates
.
Count
);
}
}
...
@@ -34,7 +34,7 @@ namespace DotNetCore.CAP.Test
...
@@ -34,7 +34,7 @@ namespace DotNetCore.CAP.Test
public
void
CanFindSpecifiedTopic
()
public
void
CanFindSpecifiedTopic
()
{
{
var
selector
=
_provider
.
GetRequiredService
<
IConsumerServiceSelector
>();
var
selector
=
_provider
.
GetRequiredService
<
IConsumerServiceSelector
>();
var
candidates
=
selector
.
SelectCandidates
(
_provider
);
var
candidates
=
selector
.
SelectCandidates
();
var
bestCandidates
=
selector
.
SelectBestCandidate
(
"Candidates.Foo"
,
candidates
);
var
bestCandidates
=
selector
.
SelectBestCandidate
(
"Candidates.Foo"
,
candidates
);
Assert
.
NotNull
(
bestCandidates
);
Assert
.
NotNull
(
bestCandidates
);
...
...
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