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
075c8275
Commit
075c8275
authored
Jul 25, 2019
by
Savorboard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support multiple consumer threads. (#295)
parent
bec28ca3
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
52 deletions
+46
-52
CAP.Options.cs
src/DotNetCore.CAP/CAP.Options.cs
+11
-25
IConsumerRegister.Default.cs
src/DotNetCore.CAP/IConsumerRegister.Default.cs
+35
-27
No files found.
src/DotNetCore.CAP/CAP.Options.cs
View file @
075c8275
...
@@ -14,34 +14,14 @@ namespace DotNetCore.CAP
...
@@ -14,34 +14,14 @@ namespace DotNetCore.CAP
/// </summary>
/// </summary>
public
class
CapOptions
public
class
CapOptions
{
{
/// <summary>
/// Default succeeded message expiration time span, in seconds.
/// </summary>
public
const
int
DefaultSucceedMessageExpirationAfter
=
24
*
3600
;
/// <summary>
/// Failed message retry waiting interval.
/// </summary>
public
const
int
DefaultFailedMessageWaitingInterval
=
60
;
/// <summary>
/// Failed message retry count.
/// </summary>
public
const
int
DefaultFailedRetryCount
=
50
;
/// <summary>
/// Default version
/// </summary>
public
const
string
DefaultVersion
=
"v1"
;
public
CapOptions
()
public
CapOptions
()
{
{
SucceedMessageExpiredAfter
=
DefaultSucceedMessageExpirationAfter
;
SucceedMessageExpiredAfter
=
24
*
3600
;
FailedRetryInterval
=
DefaultFailedMessageWaitingInterval
;
FailedRetryInterval
=
60
;
FailedRetryCount
=
DefaultFailedRetryCount
;
FailedRetryCount
=
50
;
ConsumerThreadCount
=
1
;
Extensions
=
new
List
<
ICapOptionsExtension
>();
Extensions
=
new
List
<
ICapOptionsExtension
>();
Version
=
DefaultVersion
;
Version
=
"v1"
;
DefaultGroup
=
"cap.queue."
+
Assembly
.
GetEntryAssembly
()?.
GetName
().
Name
.
ToLower
();
DefaultGroup
=
"cap.queue."
+
Assembly
.
GetEntryAssembly
()?.
GetName
().
Name
.
ToLower
();
}
}
...
@@ -80,6 +60,12 @@ namespace DotNetCore.CAP
...
@@ -80,6 +60,12 @@ namespace DotNetCore.CAP
/// </summary>
/// </summary>
public
int
FailedRetryCount
{
get
;
set
;
}
public
int
FailedRetryCount
{
get
;
set
;
}
/// <summary>
/// The number of consumer thread connections.
/// Default is 1
/// </summary>
public
int
ConsumerThreadCount
{
get
;
set
;
}
/// <summary>
/// <summary>
/// Registers an extension that will be executed when building services.
/// Registers an extension that will be executed when building services.
/// </summary>
/// </summary>
...
...
src/DotNetCore.CAP/IConsumerRegister.Default.cs
View file @
075c8275
...
@@ -11,6 +11,7 @@ using DotNetCore.CAP.Infrastructure;
...
@@ -11,6 +11,7 @@ using DotNetCore.CAP.Infrastructure;
using
DotNetCore.CAP.Internal
;
using
DotNetCore.CAP.Internal
;
using
DotNetCore.CAP.Models
;
using
DotNetCore.CAP.Models
;
using
Microsoft.Extensions.Logging
;
using
Microsoft.Extensions.Logging
;
using
Microsoft.Extensions.Options
;
namespace
DotNetCore.CAP
namespace
DotNetCore.CAP
{
{
...
@@ -21,9 +22,10 @@ namespace DotNetCore.CAP
...
@@ -21,9 +22,10 @@ namespace DotNetCore.CAP
private
readonly
IDispatcher
_dispatcher
;
private
readonly
IDispatcher
_dispatcher
;
private
readonly
ILogger
_logger
;
private
readonly
ILogger
_logger
;
private
readonly
TimeSpan
_pollingDelay
=
TimeSpan
.
FromSeconds
(
1
);
private
readonly
TimeSpan
_pollingDelay
=
TimeSpan
.
FromSeconds
(
1
);
private
readonly
CapOptions
_options
;
private
readonly
MethodMatcherCache
_selector
;
private
readonly
MethodMatcherCache
_selector
;
private
readonly
CancellationTokenSource
_cts
;
private
CancellationTokenSource
_cts
;
private
string
_serverAddress
;
private
string
_serverAddress
;
private
Task
_compositeTask
;
private
Task
_compositeTask
;
private
bool
_disposed
;
private
bool
_disposed
;
...
@@ -34,17 +36,21 @@ namespace DotNetCore.CAP
...
@@ -34,17 +36,21 @@ namespace DotNetCore.CAP
private
static
readonly
DiagnosticListener
s_diagnosticListener
=
private
static
readonly
DiagnosticListener
s_diagnosticListener
=
new
DiagnosticListener
(
CapDiagnosticListenerExtensions
.
DiagnosticListenerName
);
new
DiagnosticListener
(
CapDiagnosticListenerExtensions
.
DiagnosticListenerName
);
public
ConsumerRegister
(
IConsumerClientFactory
consumerClientFactory
,
public
ConsumerRegister
(
IOptions
<
CapOptions
>
options
,
IConsumerClientFactory
consumerClientFactory
,
IDispatcher
dispatcher
,
IDispatcher
dispatcher
,
IStorageConnection
connection
,
IStorageConnection
connection
,
ILogger
<
ConsumerRegister
>
logger
,
ILogger
<
ConsumerRegister
>
logger
,
MethodMatcherCache
selector
)
MethodMatcherCache
selector
)
{
{
_options
=
options
.
Value
;
_selector
=
selector
;
_selector
=
selector
;
_logger
=
logger
;
_logger
=
logger
;
_consumerClientFactory
=
consumerClientFactory
;
_consumerClientFactory
=
consumerClientFactory
;
_dispatcher
=
dispatcher
;
_dispatcher
=
dispatcher
;
_connection
=
connection
;
_connection
=
connection
;
_cts
=
new
CancellationTokenSource
();
}
}
public
bool
IsHealthy
()
public
bool
IsHealthy
()
...
@@ -54,11 +60,11 @@ namespace DotNetCore.CAP
...
@@ -54,11 +60,11 @@ namespace DotNetCore.CAP
public
void
Start
()
public
void
Start
()
{
{
_cts
=
new
CancellationTokenSource
();
var
groupingMatches
=
_selector
.
GetCandidatesMethodsOfGroupNameGrouped
();
var
groupingMatches
=
_selector
.
GetCandidatesMethodsOfGroupNameGrouped
();
foreach
(
var
matchGroup
in
groupingMatches
)
foreach
(
var
matchGroup
in
groupingMatches
)
{
for
(
int
i
=
0
;
i
<
_options
.
ConsumerThreadCount
;
i
++)
{
{
Task
.
Factory
.
StartNew
(()
=>
Task
.
Factory
.
StartNew
(()
=>
{
{
...
@@ -90,7 +96,7 @@ namespace DotNetCore.CAP
...
@@ -90,7 +96,7 @@ namespace DotNetCore.CAP
}
}
},
_cts
.
Token
,
TaskCreationOptions
.
LongRunning
,
TaskScheduler
.
Default
);
},
_cts
.
Token
,
TaskCreationOptions
.
LongRunning
,
TaskScheduler
.
Default
);
}
}
}
_compositeTask
=
Task
.
CompletedTask
;
_compositeTask
=
Task
.
CompletedTask
;
}
}
...
@@ -140,6 +146,8 @@ namespace DotNetCore.CAP
...
@@ -140,6 +146,8 @@ namespace DotNetCore.CAP
{
{
client
.
OnMessageReceived
+=
(
sender
,
messageContext
)
=>
client
.
OnMessageReceived
+=
(
sender
,
messageContext
)
=>
{
{
_cts
.
Token
.
ThrowIfCancellationRequested
();
var
startTime
=
DateTimeOffset
.
UtcNow
;
var
startTime
=
DateTimeOffset
.
UtcNow
;
var
stopwatch
=
Stopwatch
.
StartNew
();
var
stopwatch
=
Stopwatch
.
StartNew
();
...
...
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