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
f664b628
Commit
f664b628
authored
Jul 25, 2019
by
Savorboard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improved Ctrl+C action raised exception issue.
parent
7971d672
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
40 additions
and
22 deletions
+40
-22
IConnectionChannelPool.Default.cs
...DotNetCore.CAP.RabbitMQ/IConnectionChannelPool.Default.cs
+1
-1
ISubscribeExecutor.Default.cs
src/DotNetCore.CAP/ISubscribeExecutor.Default.cs
+16
-7
ISubscriberExecutor.cs
src/DotNetCore.CAP/ISubscriberExecutor.cs
+3
-2
IConsumerInvoker.Default.cs
src/DotNetCore.CAP/Internal/IConsumerInvoker.Default.cs
+4
-1
IConsumerInvoker.cs
src/DotNetCore.CAP/Internal/IConsumerInvoker.cs
+3
-1
IDispatcher.Default.cs
src/DotNetCore.CAP/Processor/IDispatcher.Default.cs
+6
-3
IProcessor.InfiniteRetry.cs
src/DotNetCore.CAP/Processor/IProcessor.InfiniteRetry.cs
+1
-1
IProcessor.NeedRetry.cs
src/DotNetCore.CAP/Processor/IProcessor.NeedRetry.cs
+6
-6
No files found.
src/DotNetCore.CAP.RabbitMQ/IConnectionChannelPool.Default.cs
View file @
f664b628
...
...
@@ -39,7 +39,7 @@ namespace DotNetCore.CAP.RabbitMQ
_connectionActivator
=
CreateConnection
(
options
);
HostAddress
=
$"
{
options
.
HostName
}
:
{
options
.
Port
}
"
;
Exchange
=
CapOptions
.
DefaultVersion
==
capOptions
.
Version
?
options
.
ExchangeName
:
$"
{
options
.
ExchangeName
}
.
{
capOptions
.
Version
}
"
;
Exchange
=
"v1"
==
capOptions
.
Version
?
options
.
ExchangeName
:
$"
{
options
.
ExchangeName
}
.
{
capOptions
.
Version
}
"
;
_logger
.
LogDebug
(
$"RabbitMQ configuration:'HostName:
{
options
.
HostName
}
, Port:
{
options
.
Port
}
, UserName:
{
options
.
UserName
}
, Password:
{
options
.
Password
}
, ExchangeName:
{
options
.
ExchangeName
}
'"
);
}
...
...
src/DotNetCore.CAP/ISubscribeExecutor.Default.cs
View file @
f664b628
...
...
@@ -3,6 +3,7 @@
using
System
;
using
System.Diagnostics
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
DotNetCore.CAP.Diagnostics
;
using
DotNetCore.CAP.Infrastructure
;
...
...
@@ -50,13 +51,13 @@ namespace DotNetCore.CAP
private
IConsumerInvoker
Invoker
{
get
;
}
public
async
Task
<
OperateResult
>
ExecuteAsync
(
CapReceivedMessage
message
)
public
async
Task
<
OperateResult
>
ExecuteAsync
(
CapReceivedMessage
message
,
CancellationToken
cancellationToken
)
{
bool
retry
;
OperateResult
result
;
do
{
var
executedResult
=
await
ExecuteWithoutRetryAsync
(
message
);
var
executedResult
=
await
ExecuteWithoutRetryAsync
(
message
,
cancellationToken
);
result
=
executedResult
.
Item2
;
if
(
result
==
OperateResult
.
Success
)
{
...
...
@@ -72,19 +73,22 @@ namespace DotNetCore.CAP
/// Execute message consumption once.
/// </summary>
/// <param name="message">the message received of <see cref="CapReceivedMessage"/></param>
/// <param name="cancellationToken"></param>
/// <returns>Item1 is need still retry, Item2 is executed result.</returns>
private
async
Task
<(
bool
,
OperateResult
)>
ExecuteWithoutRetryAsync
(
CapReceivedMessage
message
)
private
async
Task
<(
bool
,
OperateResult
)>
ExecuteWithoutRetryAsync
(
CapReceivedMessage
message
,
CancellationToken
cancellationToken
)
{
if
(
message
==
null
)
{
throw
new
ArgumentNullException
(
nameof
(
message
));
}
cancellationToken
.
ThrowIfCancellationRequested
();
try
{
var
sp
=
Stopwatch
.
StartNew
();
await
InvokeConsumerMethodAsync
(
message
);
await
InvokeConsumerMethodAsync
(
message
,
cancellationToken
);
sp
.
Stop
();
...
...
@@ -160,7 +164,7 @@ namespace DotNetCore.CAP
message
.
Content
=
Helper
.
AddExceptionProperty
(
message
.
Content
,
exception
);
}
private
async
Task
InvokeConsumerMethodAsync
(
CapReceivedMessage
receivedMessage
)
private
async
Task
InvokeConsumerMethodAsync
(
CapReceivedMessage
receivedMessage
,
CancellationToken
cancellationToken
)
{
if
(!
_selector
.
TryGetTopicExecutor
(
receivedMessage
.
Name
,
receivedMessage
.
Group
,
out
var
executor
))
...
...
@@ -179,15 +183,20 @@ namespace DotNetCore.CAP
{
operationId
=
s_diagnosticListener
.
WriteSubscriberInvokeBefore
(
consumerContext
);
var
ret
=
await
Invoker
.
InvokeAsync
(
consumerContext
);
var
ret
=
await
Invoker
.
InvokeAsync
(
consumerContext
,
cancellationToken
);
s_diagnosticListener
.
WriteSubscriberInvokeAfter
(
operationId
,
consumerContext
,
startTime
,
stopwatch
.
Elapsed
);
s_diagnosticListener
.
WriteSubscriberInvokeAfter
(
operationId
,
consumerContext
,
startTime
,
stopwatch
.
Elapsed
);
if
(!
string
.
IsNullOrEmpty
(
ret
.
CallbackName
))
{
await
_callbackMessageSender
.
SendAsync
(
ret
.
MessageId
,
ret
.
CallbackName
,
ret
.
Result
);
}
}
catch
(
OperationCanceledException
)
{
//ignore
}
catch
(
Exception
ex
)
{
s_diagnosticListener
.
WriteSubscriberInvokeError
(
operationId
,
consumerContext
,
ex
,
startTime
,
stopwatch
.
Elapsed
);
...
...
src/DotNetCore.CAP/ISubscriberExecutor.cs
View file @
f664b628
// Copyright (c) .NET Core Community. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
using
System.Threading
;
using
System.Threading.Tasks
;
using
DotNetCore.CAP.Models
;
namespace
DotNetCore.CAP
{
/// <summary>
/// Consumer exec
o
tor
/// Consumer exec
u
tor
/// </summary>
public
interface
ISubscriberExecutor
{
Task
<
OperateResult
>
ExecuteAsync
(
CapReceivedMessage
message
);
Task
<
OperateResult
>
ExecuteAsync
(
CapReceivedMessage
message
,
CancellationToken
cancellationToken
=
default
);
}
}
\ No newline at end of file
src/DotNetCore.CAP/Internal/IConsumerInvoker.Default.cs
View file @
f664b628
...
...
@@ -3,6 +3,7 @@
using
System
;
using
System.Linq
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
DotNetCore.CAP.Abstractions
;
using
Microsoft.Extensions.DependencyInjection
;
...
...
@@ -29,8 +30,10 @@ namespace DotNetCore.CAP.Internal
_logger
=
loggerFactory
.
CreateLogger
<
DefaultConsumerInvoker
>();
}
public
async
Task
<
ConsumerExecutedResult
>
InvokeAsync
(
ConsumerContext
context
)
public
async
Task
<
ConsumerExecutedResult
>
InvokeAsync
(
ConsumerContext
context
,
CancellationToken
cancellationToken
=
default
)
{
cancellationToken
.
ThrowIfCancellationRequested
();
_logger
.
LogDebug
(
"Executing consumer Topic: {0}"
,
context
.
ConsumerDescriptor
.
MethodInfo
.
Name
);
var
executor
=
ObjectMethodExecutor
.
Create
(
...
...
src/DotNetCore.CAP/Internal/IConsumerInvoker.cs
View file @
f664b628
// Copyright (c) .NET Core Community. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
using
System.Threading
;
using
System.Threading.Tasks
;
namespace
DotNetCore.CAP.Internal
...
...
@@ -14,6 +15,7 @@ namespace DotNetCore.CAP.Internal
/// Invoke consumer method whit consumer context.
/// </summary>
/// <param name="context">consumer execute context</param>
Task
<
ConsumerExecutedResult
>
InvokeAsync
(
ConsumerContext
context
);
/// <param name="cancellationToken">The object of <see cref="CancellationToken"/>.</param>
Task
<
ConsumerExecutedResult
>
InvokeAsync
(
ConsumerContext
context
,
CancellationToken
cancellationToken
=
default
);
}
}
\ No newline at end of file
src/DotNetCore.CAP/Processor/IDispatcher.Default.cs
View file @
f664b628
...
...
@@ -57,11 +57,14 @@ namespace DotNetCore.CAP.Processor
{
while
(!
_publishedMessageQueue
.
IsCompleted
)
{
if
(
_publishedMessageQueue
.
TryTake
(
out
var
message
,
1
00
,
_cts
.
Token
))
if
(
_publishedMessageQueue
.
TryTake
(
out
var
message
,
30
00
,
_cts
.
Token
))
{
try
{
_sender
.
SendAsync
(
message
);
Task
.
Run
(
async
()
=>
{
await
_sender
.
SendAsync
(
message
);
});
}
catch
(
Exception
ex
)
{
...
...
@@ -82,7 +85,7 @@ namespace DotNetCore.CAP.Processor
{
foreach
(
var
message
in
_receivedMessageQueue
.
GetConsumingEnumerable
(
_cts
.
Token
))
{
_executor
.
ExecuteAsync
(
message
);
_executor
.
ExecuteAsync
(
message
,
_cts
.
Token
);
}
}
catch
(
OperationCanceledException
)
...
...
src/DotNetCore.CAP/Processor/IProcessor.InfiniteRetry.cs
View file @
f664b628
...
...
@@ -30,7 +30,7 @@ namespace DotNetCore.CAP.Processor
}
catch
(
OperationCanceledException
)
{
return
;
//ignore
}
catch
(
Exception
ex
)
{
...
...
src/DotNetCore.CAP/Processor/IProcessor.NeedRetry.cs
View file @
f664b628
...
...
@@ -40,15 +40,15 @@ namespace DotNetCore.CAP.Processor
var
connection
=
context
.
Provider
.
GetRequiredService
<
IStorageConnection
>();
await
Task
.
WhenAll
(
ProcessPublishedAsync
(
connection
,
context
),
ProcessReceivedAsync
(
connection
,
context
));
await
Task
.
WhenAll
(
ProcessPublishedAsync
(
connection
,
context
),
ProcessReceivedAsync
(
connection
,
context
));
await
context
.
WaitAsync
(
_waitingInterval
);
}
private
async
Task
ProcessPublishedAsync
(
IStorageConnection
connection
,
ProcessingContext
context
)
{
context
.
ThrowIfStopping
();
var
messages
=
await
GetSafelyAsync
(
connection
.
GetPublishedMessagesOfNeedRetry
);
foreach
(
var
message
in
messages
)
...
...
@@ -61,14 +61,14 @@ namespace DotNetCore.CAP.Processor
private
async
Task
ProcessReceivedAsync
(
IStorageConnection
connection
,
ProcessingContext
context
)
{
context
.
ThrowIfStopping
();
var
messages
=
await
GetSafelyAsync
(
connection
.
GetReceivedMessagesOfNeedRetry
);
foreach
(
var
message
in
messages
)
{
await
_subscriberExecutor
.
ExecuteAsync
(
message
);
context
.
ThrowIfStopping
();
await
context
.
WaitAsync
(
_delay
);
}
}
...
...
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