Commit 09045920 by dingsongjie

添加 grpc 测试

parent 92296200
......@@ -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>
......
......@@ -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);
}
......
......@@ -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;
......
......@@ -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();
});
});
});
......
......@@ -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;
//}
}
......@@ -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();
});
}
}
......
......@@ -4,7 +4,8 @@
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information",
"Grpc": "Information"
"Grpc": "Information",
"Microsoft.AspNetCore.Server.Kestrel": "Debug"
}
},
"postgres": {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment