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
09045920
authored
Mar 03, 2020
by
dingsongjie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加 grpc 测试
parent
92296200
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
33 additions
and
24 deletions
samples/apis/Backet.Api/Backet.Api.csproj
samples/apis/Backet.Api/EventHandlers/ToNoticeBacketCreatedEventHandler.cs
samples/apis/Backet.Api/GrpcServices/BacketService.cs
samples/apis/Backet.Api/Program.cs
samples/apis/Backet.Api/Protos/backet.proto
samples/apis/Backet.Api/Startup.cs
samples/apis/Backet.Api/appsettings.json
samples/apis/Backet.Api/Backet.Api.csproj
View file @
09045920
...
...
@@ -16,11 +16,11 @@
</ItemGroup>
<ItemGroup>
<None Remove="Protos\commonCommandResponse.proto"
AdditionalImportDirs="Protos"
GrpcServices="Server" />
<None Remove="Protos\commonCommandResponse.proto" GrpcServices="Server" />
</ItemGroup>
<ItemGroup>
<Protobuf Include="Protos\*" GrpcServices="Server" />
<Protobuf Include="Protos\*"
AdditionalImportDirs="Protos"
GrpcServices="Server" />
</ItemGroup>
<ItemGroup>
...
...
samples/apis/Backet.Api/EventHandlers/ToNoticeBacketCreatedEventHandler.cs
View file @
09045920
...
...
@@ -11,7 +11,7 @@ namespace Backet.Api.EventHandlers
public
class
ToNoticeBacketCreatedEventHandler
:
PoleEventHandler
<
BacketCreatedEvent
>,
IToNoticeBacketCreatedEventHandler
{
public
async
Task
BulkEventsHandle
(
List
<
BacketCreatedEvent
>
@event
)
{
{
await
Task
.
Delay
(
1500
);
}
...
...
samples/apis/Backet.Api/GrpcServices/BacketService.cs
View file @
09045920
...
...
@@ -19,7 +19,7 @@ namespace Backet.Api.GrpcServices
public
override
async
Task
<
Pole
.
Grpc
.
ExtraType
.
CommonCommandResponse
>
AddBacket
(
AddBacketRequest
backetDto
,
ServerCallContext
context
)
{
var
newId
=
Guid
.
NewGuid
().
ToString
(
"N"
).
ToLower
();
backetDto
.
Id
=
newId
;
//
backetDto.Id = newId;
var
grain
=
clusterClient
.
GetGrain
<
IAddBacketGrain
>(
newId
);
//await grain.AddBacket(backetDto);
return
Pole
.
Grpc
.
ExtraType
.
CommonCommandResponse
.
SuccessResponse
;
...
...
samples/apis/Backet.Api/Program.cs
View file @
09045920
...
...
@@ -25,14 +25,14 @@ namespace Backet.Api
Host
.
CreateDefaultBuilder
(
args
)
.
UseOrleans
(
siloBuilder
=>
{
siloBuilder
.
ConfigureApplicationParts
(
parts
=>
parts
.
AddFromApplicationBaseDirectory
())
;
siloBuilder
.
UseLocalhostClustering
();
siloBuilder
.
AddEfGrainStorage
<
BacketDbContext
>(
"ef"
);
siloBuilder
.
Configure
<
GrainCollectionOptions
>(
options
=>
{
options
.
CollectionAge
=
TimeSpan
.
FromMinutes
(
2
);
});
siloBuilder
.
UseDashboard
(
options
=>
{
});
siloBuilder
.
ConfigureApplicationParts
(
parts
=>
parts
.
AddFromApplicationBaseDirectory
())
.
UseLocalhostClustering
()
.
AddEfGrainStorage
<
BacketDbContext
>(
"ef"
)
.
Configure
<
GrainCollectionOptions
>(
options
=>
{
options
.
CollectionAge
=
TimeSpan
.
FromSeconds
(
65
);
})
.
UseDashboard
(
options
=>
{
});
})
.
ConfigureWebHostDefaults
(
webBuilder
=>
{
...
...
@@ -46,6 +46,7 @@ namespace Backet.Api
option
.
ListenAnyIP
(
82
,
config
=>
{
config
.
Protocols
=
Microsoft
.
AspNetCore
.
Server
.
Kestrel
.
Core
.
HttpProtocols
.
Http2
;
config
.
UseHttps
();
});
});
});
...
...
samples/apis/Backet.Api/Protos/backet.proto
View file @
09045920
...
...
@@ -2,7 +2,7 @@ syntax = "proto3";
option
csharp_namespace
=
"Backet.Grpc"
;
import
"
Protos/
Common/commonCommandResponse.proto"
;
import
"Common/commonCommandResponse.proto"
;
package
greet
;
// The greeting service definition.
...
...
@@ -14,13 +14,13 @@ service Backet {
// The request message containing the user's name.
message
AddBacketRequest
{
string
name
=
1
;
string
id
=
2
;
string
userId
=
3
;
repeated
AddBacketItemRequest
Items
=
4
;
message
AddBacketItemRequest
{
string
productId
=
1
;
string
productName
=
2
;
int64
price
=
3
;
}
//
string id = 2;
//
string userId = 3;
//
repeated AddBacketItemRequest Items = 4;
//
message AddBacketItemRequest{
//
string productId = 1;
//
string productName = 2;
//
int64 price = 3;
//
}
}
samples/apis/Backet.Api/Startup.cs
View file @
09045920
...
...
@@ -32,7 +32,13 @@ namespace Backet.Api
services
.
AddGrpcValidation
();
services
.
AddGrpcRequestValidator
();
services
.
AddGrpcWeb
(
o
=>
o
.
GrpcWebEnabled
=
true
);
services
.
AddCors
(
o
=>
o
.
AddPolicy
(
"AllowAll"
,
builder
=>
{
builder
.
AllowAnyOrigin
()
.
AllowAnyMethod
()
.
AllowAnyHeader
()
.
WithExposedHeaders
(
"Grpc-Status"
,
"Grpc-Message"
);
}));
services
.
AddPole
(
config
=>
{
config
.
AddRabbitMQ
(
option
=>
...
...
@@ -66,11 +72,12 @@ namespace Backet.Api
app
.
UseRouting
();
app
.
UseGrpcWeb
();
app
.
UseCors
(
"AllowAll"
);
app
.
UseEndpoints
(
endpoints
=>
{
endpoints
.
MapDefaultControllerRoute
();
endpoints
.
MapGrpcService
<
BacketService
>();
endpoints
.
MapGrpcService
<
BacketService
>()
.
EnableGrpcWeb
()
;
});
}
}
...
...
samples/apis/Backet.Api/appsettings.json
View file @
09045920
...
...
@@ -4,7 +4,8 @@
"Default"
:
"Information"
,
"Microsoft"
:
"Warning"
,
"Microsoft.Hosting.Lifetime"
:
"Information"
,
"Grpc"
:
"Information"
"Grpc"
:
"Information"
,
"Microsoft.AspNetCore.Server.Kestrel"
:
"Debug"
}
},
"postgres"
:
{
...
...
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