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
cedd3b9e
authored
Feb 20, 2020
by
dingsongjie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加 发送 event 测试实例
parent
d4fa1681
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
47 additions
and
10 deletions
samples/apis/Backet.Api/Backet.Api.csproj
samples/apis/Backet.Api/Controllers/BacketController.cs
samples/apis/Backet.Api/Domain/Event/BacketCreatedEvent.cs
samples/apis/Backet.Api/EventHandlers/ToNoticeBacketCreatedEventHandler.cs
samples/apis/Backet.Api/Grains/BacketGrain.cs
src/Pole.Core/Processor/PendingMessageRetryProcessor.cs
src/Pole.Core/UnitOfWork/UnitOfWork.cs
samples/apis/Backet.Api/Backet.Api.csproj
View file @
cedd3b9e
...
...
@@ -5,6 +5,13 @@
</PropertyGroup>
<ItemGroup>
<Compile Remove="Application\**" />
<Content Remove="Application\**" />
<EmbeddedResource Remove="Application\**" />
<None Remove="Application\**" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Grpc.AspNetCore" Version="2.26.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.1">
<PrivateAssets>all</PrivateAssets>
...
...
@@ -26,8 +33,5 @@
<ProjectReference Include="..\..\..\src\Pole.EventStorage.PostgreSql\Pole.EventStorage.PostgreSql.csproj" />
<ProjectReference Include="..\..\..\src\Pole.Orleans.Provider.EntityframeworkCore\Pole.Orleans.Provider.EntityframeworkCore.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Application\IntegrationEvent\" />
</ItemGroup>
</Project>
samples/apis/Backet.Api/Controllers/BacketController.cs
View file @
cedd3b9e
...
...
@@ -21,7 +21,7 @@ namespace Backet.Api.Controllers
[
HttpPost
(
"api/backet/AddBacket"
)]
public
Task
<
bool
>
AddBacket
([
FromBody
]
Backet
.
Api
.
Grains
.
Abstraction
.
BacketDto
backet
)
{
var
newId
=
"da8a489fa7b44092
94ee1b358fbbfba5
"
;
var
newId
=
"da8a489fa7b44092
eeeeeee
"
;
backet
.
Id
=
newId
;
var
grain
=
clusterClient
.
GetGrain
<
IBacketGrain
>(
newId
);
return
grain
.
AddBacket
(
backet
);
...
...
samples/apis/Backet.Api/Domain/Event/BacketCreatedEvent.cs
0 → 100644
View file @
cedd3b9e
using
Pole.Core.EventBus.Event
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Threading.Tasks
;
namespace
Backet.Api.Domain.Event
{
public
class
BacketCreatedEvent
:
IEvent
{
public
string
BacketId
{
get
;
set
;
}
}
}
samples/apis/Backet.Api/EventHandlers/ToNoticeBacketCreatedEventHandler.cs
0 → 100644
View file @
cedd3b9e
using
Backet.Api.Domain.Event
;
using
Pole.Core.EventBus.EventHandler
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Threading.Tasks
;
namespace
Backet.Api.EventHandlers
{
public
class
ToNoticeBacketCreatedEventHandler
:
PoleEventHandler
{
public
Task
EventHandle
(
BacketCreatedEvent
@event
)
{
return
Task
.
CompletedTask
;
}
}
}
samples/apis/Backet.Api/Grains/BacketGrain.cs
View file @
cedd3b9e
using
Backet.Api.Grains.Abstraction
;
using
Backet.Api.Domain.Event
;
using
Backet.Api.Grains.Abstraction
;
using
Pole.Core.Grains
;
using
System
;
using
System.Collections.Generic
;
...
...
@@ -16,18 +17,20 @@ namespace Backet.Api.Grains
Backet
.
Api
.
Domain
.
AggregatesModel
.
BacketAggregate
.
Backet
backet
=
new
Backet
.
Api
.
Domain
.
AggregatesModel
.
BacketAggregate
.
Backet
{
Id
=
backetDto
.
Id
,
UserId
=
backetDto
.
UserId
UserId
=
backetDto
.
UserId
};
if
(
backetDto
.
BacketItems
==
null
||
backetDto
.
BacketItems
.
Count
==
0
)
return
false
;
backetDto
.
BacketItems
.
ForEach
(
item
=>
{
backetDto
.
BacketItems
.
ForEach
(
item
=>
{
backet
.
AddBacketItem
(
item
.
ProductId
,
item
.
ProductName
,
item
.
Price
);
});
Add
(
backet
);
backet
.
AddDomainEvent
(
new
BacketCreatedEvent
()
{
BacketId
=
backet
.
Id
});
await
WriteStateAsync
();
return
true
;
}
public
async
Task
<
bool
>
AddBacketItem
(
string
productId
,
string
productName
,
long
price
)
public
async
Task
<
bool
>
AddBacketItem
(
string
productId
,
string
productName
,
long
price
)
{
if
(
State
==
null
)
return
false
;
...
...
src/Pole.Core/Processor/PendingMessageRetryProcessor.cs
View file @
cedd3b9e
...
...
@@ -63,7 +63,7 @@ namespace Pole.Core.Processor
foreach
(
var
pendingMessage
in
pendingMessages
)
{
var
eventType
=
eventTypeFinder
.
FindType
(
pendingMessage
.
Name
);
var
eventContentBytes
=
serializer
.
SerializeToUtf8Bytes
(
pendingMessage
,
eventType
);
var
eventContentBytes
=
Encoding
.
UTF8
.
GetBytes
(
pendingMessage
.
Content
);
var
bytesTransport
=
new
EventBytesTransport
(
pendingMessage
.
Name
,
pendingMessage
.
Id
,
eventContentBytes
);
var
bytes
=
bytesTransport
.
GetBytes
();
if
(
pendingMessage
.
Retries
>
producerOptions
.
MaxFailedRetryCount
)
...
...
src/Pole.Core/UnitOfWork/UnitOfWork.cs
View file @
cedd3b9e
...
...
@@ -42,7 +42,7 @@ namespace Pole.Core.UnitOfWork
bufferedEvents
.
ForEach
(
async
@event
=>
{
var
eventType
=
eventTypeFinder
.
FindType
(
@event
.
Name
);
var
eventContentBytes
=
serializer
.
SerializeToUtf8Bytes
(
@event
,
eventType
);
var
eventContentBytes
=
Encoding
.
UTF8
.
GetBytes
(
@event
.
Content
);
var
bytesTransport
=
new
EventBytesTransport
(
@event
.
Name
,
@event
.
Id
,
eventContentBytes
);
var
bytes
=
bytesTransport
.
GetBytes
();
var
producer
=
await
producerContainer
.
GetProducer
(
eventType
);
...
...
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