Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
丁松杰
/
Pole
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
cdda9bcf
authored
5 years ago
by
dingsongjie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix bug
parent
672f72c7
master
…
v1.0.0
v0.0.1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
16 deletions
src/Pole.Application/EventBus/EventEntry.cs
src/Pole.Application/EventBus/ReliableMessageTransactionWorker.cs
src/Pole.Application/EventBus/EventEntry.cs
View file @
cdda9bcf
...
...
@@ -9,7 +9,6 @@ namespace Pole.Application.EventBus
public
object
Event
{
get
;
private
set
;
}
public
object
CallbackParemeter
{
get
;
private
set
;
}
public
string
PrePublishEventId
{
get
;
set
;
}
public
bool
IsPublished
{
get
;
set
;
}
public
Type
EventType
{
get
;
private
set
;
}
public
EventEntry
(
object
@event
,
object
callbackParemeter
,
Type
eventType
)
{
...
...
This diff is collapsed.
Click to expand it.
src/Pole.Application/EventBus/ReliableMessageTransactionWorker.cs
View file @
cdda9bcf
using
Pole.Domain.UnitOfWork
;
using
Microsoft.Extensions.Logging
;
using
Pole.Domain.UnitOfWork
;
using
Pole.ReliableMessage.Abstraction
;
using
System
;
using
System.Collections.Generic
;
...
...
@@ -13,11 +14,13 @@ namespace Pole.Application.EventBus
{
private
readonly
IReliableMessageScopedBuffer
_reliableMessageScopedBuffer
;
private
readonly
IReliableBus
_reliableBus
;
private
readonly
ILogger
<
ReliableMessageTransactionWorker
>
_logger
;
public
ReliableMessageTransactionWorker
(
IReliableMessageScopedBuffer
reliableMessageScopedBuffer
,
IReliableBus
reliableBus
)
public
ReliableMessageTransactionWorker
(
IReliableMessageScopedBuffer
reliableMessageScopedBuffer
,
IReliableBus
reliableBus
,
ILogger
<
ReliableMessageTransactionWorker
>
logger
)
{
_reliableMessageScopedBuffer
=
reliableMessageScopedBuffer
;
_reliableBus
=
reliableBus
;
_logger
=
logger
;
}
public
int
Order
=>
200
;
...
...
@@ -32,23 +35,13 @@ namespace Pole.Application.EventBus
var
tasks
=
events
.
Select
(
async
@event
=>
{
await
_reliableBus
.
Publish
(
@event
.
Event
,
@event
.
PrePublishEventId
,
cancellationToken
);
@event
.
IsPublished
=
true
;
});
await
Task
.
WhenAll
(
tasks
);
}
catch
(
Exception
ex
)
{
if
(
events
.
Count
(
@event
=>
@event
.
IsPublished
)
>
1
)
{
//这里发布失败 通过预发送后的重试机制去处理, 因为一旦有一个消息发出去后 无法挽回
return
;
}
else
{
// 这里抛出错误 ,统一工作单元拦截后会 回滚整个工作单元
throw
ex
;
}
_logger
.
LogError
(
ex
,
"ReliableMessageTransactionWorker.Commit error"
);
// 此时 预发送成功 ,数据库事务提交成功 ,发送消息至消息队列失败 ,任然返回成功 ,因为预发送消息 的重试机制会让 消息发送成功
}
WorkerStatus
=
WorkerStatus
.
Commited
;
return
;
...
...
@@ -75,7 +68,6 @@ namespace Pole.Application.EventBus
events
.
Where
(
m
=>
!
string
.
IsNullOrEmpty
(
m
.
PrePublishEventId
)).
ToList
().
ForEach
(
async
@event
=>
{
await
_reliableBus
.
Cancel
(
@event
.
PrePublishEventId
,
cancellationToken
);
@event
.
IsPublished
=
true
;
});
WorkerStatus
=
WorkerStatus
.
Rollbacked
;
return
Task
.
FromResult
(
1
);
...
...
This diff is collapsed.
Click to expand it.
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