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
11a37496
Commit
11a37496
authored
Apr 26, 2019
by
Tim Stubbs
Committed by
Savorboard
Apr 26, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handle messages retrieval failure (#324)
parent
30b308d7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
3 deletions
+23
-3
IProcessor.NeedRetry.cs
src/DotNetCore.CAP/Processor/IProcessor.NeedRetry.cs
+23
-3
No files found.
src/DotNetCore.CAP/Processor/IProcessor.NeedRetry.cs
View file @
11a37496
// Copyright (c) .NET Core Community. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
using
Microsoft.Extensions.DependencyInjection
;
using
Microsoft.Extensions.Logging
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Threading.Tasks
;
using
Microsoft.Extensions.DependencyInjection
;
namespace
DotNetCore.CAP.Processor
{
public
class
NeedRetryMessageProcessor
:
IProcessor
{
private
readonly
TimeSpan
_delay
=
TimeSpan
.
FromSeconds
(
1
);
private
readonly
ILogger
<
NeedRetryMessageProcessor
>
_logger
;
private
readonly
IPublishMessageSender
_publishMessageSender
;
private
readonly
ISubscriberExecutor
_subscriberExecutor
;
private
readonly
TimeSpan
_waitingInterval
;
public
NeedRetryMessageProcessor
(
CapOptions
options
,
ILogger
<
NeedRetryMessageProcessor
>
logger
,
ISubscriberExecutor
subscriberExecutor
,
IPublishMessageSender
publishMessageSender
)
{
_logger
=
logger
;
_subscriberExecutor
=
subscriberExecutor
;
_publishMessageSender
=
publishMessageSender
;
_waitingInterval
=
TimeSpan
.
FromSeconds
(
options
.
FailedRetryInterval
);
...
...
@@ -42,7 +48,7 @@ namespace DotNetCore.CAP.Processor
private
async
Task
ProcessPublishedAsync
(
IStorageConnection
connection
,
ProcessingContext
context
)
{
var
messages
=
await
connection
.
GetPublishedMessagesOfNeedRetry
(
);
var
messages
=
await
GetSafelyAsync
(()
=>
connection
.
GetPublishedMessagesOfNeedRetry
()
);
foreach
(
var
message
in
messages
)
{
...
...
@@ -56,7 +62,7 @@ namespace DotNetCore.CAP.Processor
private
async
Task
ProcessReceivedAsync
(
IStorageConnection
connection
,
ProcessingContext
context
)
{
var
messages
=
await
connection
.
GetReceivedMessagesOfNeedRetry
(
);
var
messages
=
await
GetSafelyAsync
(()
=>
connection
.
GetReceivedMessagesOfNeedRetry
()
);
foreach
(
var
message
in
messages
)
{
...
...
@@ -67,5 +73,19 @@ namespace DotNetCore.CAP.Processor
await
context
.
WaitAsync
(
_delay
);
}
}
private
async
Task
<
IEnumerable
<
T
>>
GetSafelyAsync
<
T
>(
Func
<
Task
<
IEnumerable
<
T
>>>
getMessagesAsync
)
{
try
{
return
await
getMessagesAsync
();
}
catch
(
Exception
ex
)
{
_logger
.
LogWarning
(
1
,
ex
,
"Get messages of type '{messageType}' failed. Retrying..."
,
typeof
(
T
).
Name
);
return
Enumerable
.
Empty
<
T
>();
}
}
}
}
\ No newline at end of file
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