grpc模块调试

This commit is contained in:
cbs 2024-12-26 17:50:50 +08:00
parent 48a222ee31
commit 9889059f53
10 changed files with 361 additions and 40 deletions

View File

@ -40,6 +40,13 @@
<version>${revision}</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
<!-- 业务组件 -->
<!--<dependency>
<groupId>cn.iocoder.cloud</groupId>
@ -144,10 +151,10 @@
</dependency>
<!-- 监控相关 -->
<dependency>
<!--<dependency>
<groupId>cn.iocoder.cloud</groupId>
<artifactId>yudao-spring-boot-starter-monitor</artifactId>
</dependency>
</dependency>-->
<!-- 三方云服务相关 -->
<!--<dependency>

View File

@ -24,7 +24,7 @@ public class GeometryController {
private GeometryService geometryService;
@PostMapping("/onVehiclePoseUpdated")
//@Operation(summary = "测试GRPC调用")
@Operation(summary = "测试GRPC调用")
// @PermitAll
public CommonResult<String> onVehiclePoseUpdated() {
return success(geometryService.onVehiclePoseUpdated());

View File

@ -1,28 +1,68 @@
package cn.iocoder.yudao.module.grpc.service.geometry;
import com.alibaba.fastjson.JSON;
import com.google.protobuf.DoubleValue;
import device.proto.model.common.Geometry;
import device.proto.model.common.Types;
import io.grpc.Channel;
import net.devh.boot.grpc.examples.lib.HelloRequest;
import net.devh.boot.grpc.examples.lib.MyServiceGrpc;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import device.proto.api.al.robotics.universal.nav.ChassisNavigationServiceGrpc;
import net.devh.springboot.autoconfigure.grpc.client.GrpcClient;
import org.springframework.stereotype.Service;
import java.util.Iterator;
import static sun.audio.AudioDevice.device;
@Service
public class GeometryServiceImpl implements GeometryService{
@GrpcClient("zn-robot")
@GrpcClient("ChassisNavigationService")
private Channel serverChannel;
/*@GrpcClient("global")
private ChassisNavigationServiceGrpc.ChassisNavigationServiceBlockingStub blockingStub;*/
@Override
public String onVehiclePoseUpdated() {
return receiveGreeting("test");
/*ChassisNavigationServiceGrpc.ChassisNavigationServiceBlockingStub myServiceStub = ChassisNavigationServiceGrpc.newBlockingStub(this.serverChannel);
HelloRequest request = HelloRequest.newBuilder()
.build();
Iterator<HelloReply> helloReplyIterator = myServiceStub.onVehiclePoseUpdated(null);
while (helloReplyIterator.hasNext()) {
HelloReply helloReply = helloReplyIterator.next();
System.out.println("返回的 " + JSON.toJSONString(helloReply));
}*/
/*ChassisNavigationServiceGrpc.ChassisNavigationServiceBlockingStub myServiceStub = ChassisNavigationServiceGrpc.newBlockingStub(this.serverChannel);
NavigateThroughPosesRequest request = NavigateThroughPosesRequest.newBuilder()
.build();
HelloReply helloReply1 = myServiceStub.navigateThroughPoses(request);*/
ChassisNavigationServiceGrpc.ChassisNavigationServiceBlockingStub myServiceStub = null;
try {
myServiceStub = ChassisNavigationServiceGrpc.newBlockingStub(this.serverChannel);
Iterator<Geometry.Pose2d> pose2dIterator = myServiceStub.onVehiclePoseUpdated(null);
while (pose2dIterator.hasNext()) {
Geometry.Pose2d next = pose2dIterator.next();
System.out.println("返回的 " + JSON.toJSONString(next));
}
} catch (Exception e) {
}
public String receiveGreeting(String name) {
MyServiceGrpc.MyServiceBlockingStub myServiceStub = MyServiceGrpc.newBlockingStub(this.serverChannel);
HelloRequest request = HelloRequest.newBuilder()
.setName(name)
.build();
return myServiceStub.sayHello(request).getMessage();
System.out.println("--------1111--------------");
DoubleValue build = DoubleValue.newBuilder().build();
Types.Nothing nothing = myServiceStub.forkControl(build);
System.out.println("返回的222 " + JSON.toJSONString(nothing));
// return JSON.toJSONString(helloReplyIterator);
return null;
}
}

View File

@ -4,14 +4,16 @@ grpc:
client:
# 服务名(不同服务名可对应不同配置)
# zn-zeu是服务端配置的名字GrpcClient注解会用到
zn-robot:
ChassisNavigationService:
# gRPC服务端地址
# address: 'dns://127.0.0.1:19898'
# host: 192.168.10.211
# port: 6914
address: 'static://192.168.10.211:6914'
# 是否开启保持连接(长连接)
enableKeepAlive: true
# 保持连接时长默认20s
keepAliveTimeout: 10
keepAliveTimeout: 20
# 没有RPC调用时是否保持连接默认false可禁用避免额外消耗CPU
keepAliveWithoutCalls: false
# 客户端负载均衡策略(round_robin默认, pick_first)

View File

@ -41,6 +41,18 @@
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>3.13.0</version>
</dependency>
</dependencies>
<build>

View File

@ -1,24 +0,0 @@
syntax = "proto3";
package net.devh.boot.grpc.example;
option java_multiple_files = true;
option java_package = "net.devh.boot.grpc.examples.lib";
option java_outer_classname = "HelloWorldProto";
// The greeting service definition.
service MyService {
// Sends a greeting
rpc SayHello (HelloRequest) returns (HelloReply) {
}
}
// The request message containing the user's name.
message HelloRequest {
string name = 1;
}
// The response message containing the greetings
message HelloReply {
string message = 1;
}

View File

@ -0,0 +1,67 @@
syntax = "proto3";
package device.proto.model.common;
option csharp_namespace = "Al.Proto.Model.Common";
//import "google/protobuf/struct.proto";
//2d点
message Point2d {
double x = 1;
double y = 2;
}
//2d位姿
message Pose2d {
double x = 1;//x
double y = 2;//y
double yaw = 3;//
}
//2d直线
message Line2d {
repeated Point2d points = 1;
}
//
message Polygon2d {
repeated Point2d vertex = 1;
}
message Quaternion {
double x = 1;
double y = 2;
double z = 3;
double w = 4;
}
message Rotation {
double roll = 1;
double pitch = 2;
double yaw = 3;
}
message EulerPose {
option deprecated = true;
double x = 1;
double y = 2;
double z = 3;
double roll = 4;
double pitch = 5;
double yaw = 6;
}
message Vector3d {
double x = 1;
double y = 2;
double z = 3;
}
message Pose {
double x = 1;
double y = 2;
double z = 3;
double roll = 4;
double pitch = 5;
double yaw = 6;
}

View File

@ -0,0 +1,138 @@
syntax = "proto3";
package device.proto.model.common.schema;
option csharp_namespace = "Al.Proto.Model.Common.Schema";
//
message EnumValue {
//
int64 value = 1;
//
string text = 2;
//
string remark = 3;
}
//
message TypeAttribute {
//
enum Category {
//
UNKNOWN = 0;
//
BOOLEAN = 1;
//8
INT8 = 2;
//8
UINT8 = 3;
//16
INT16 = 4;
//16
UINT16 = 5;
//32
INT32 = 6;
//32
UINT32 = 7;
//64
INT64 = 8;
//64
UINT64 = 9;
//
FLOAT = 10;
//
STRING = 15;
//
ENUM = 20;
///
ARRAY = 25;
//
MAP = 26;
//
VARIANT = 29;
//
OBJECT = 30;
}
//
message InitialValue {
oneof kind_of_initial {
//
double floating = 1;
//
uint64 integer = 2;
//
string text = 3;
//
EnumValue enum_value = 4;
//
bool boolean = 5;
}
}
//
message OptionValue {
oneof kind_of_value {
//
double floating = 1;
//
uint64 integer = 2;
//
string text = 3;
//
EnumValue enum_value = 4;
}
}
//
string definition = 1;
//
Category category = 2;
//
string remark = 3;
//
InitialValue initial = 4;
//
repeated string dependencies = 5;
//
string note = 6;
///
bool necessary = 11;
//
bool readonly = 13;
//
string pattern = 15;
oneof kind_of_range_min {
//
int64 min_integer_value = 17;
//
double min_float_value = 18;
}
oneof kind_of_range_max {
//
uint64 max_integer_value = 19;
//
double max_float_value = 20;
}
//
bool extendable = 21;
//
repeated OptionValue options = 22;
//
map<string, string> decorators = 23;
}
//
message TypeSchema {
//
TypeAttribute attr = 1;
//
map<string, TypeAttribute> fields = 4;
}

View File

@ -0,0 +1,45 @@
syntax = "proto3";
package device.proto.model.common;
option csharp_namespace = "Al.Proto.Model.Common";
//import "google/protobuf/struct.proto";
import "model/common/geometry.proto";
//
message Exception {
//
string rtti = 1;
//
string message = 2;
//
int32 code = 3;
//
string category = 4;
}
message Nothing {
}
//
message Strings {
repeated string values = 1;
}
//
message Indexes {
repeated int32 values = 1;
}
//
message Number {
oneof variant {
int32 i32 = 1;
uint32 u32 = 2;
int64 i64 = 3;
int64 u64 = 4;
double floating = 5;
}
}

View File

@ -0,0 +1,34 @@
syntax = "proto3";
package device.proto.api.al.robotics.universal.nav;
option csharp_namespace = "Al.Proto.Api.Robotics.Nav";
import "google/protobuf/empty.proto";
import "google/protobuf/wrappers.proto";
import "model/common/geometry.proto";
import "model/common/types.proto";
import "google/protobuf/struct.proto";
//姿
message NavigateThroughPosesRequest {
//姿
repeated device.proto.model.common.Pose2d pose2ds = 1;
}
service ChassisNavigationService {
//姿
rpc OnVehiclePoseUpdated(google.protobuf.Empty) returns (stream device.proto.model.common.Pose2d) {}
//姿
rpc OnTrackingPoseUpdated(google.protobuf.Empty) returns (stream device.proto.model.common.Pose2d) {}
//姿
rpc NavigateToPose(device.proto.model.common.Pose2d) returns (device.proto.model.common.Nothing) {}
//
rpc NavigateThroughPoses(NavigateThroughPosesRequest) returns (device.proto.model.common.Nothing) {}
//
rpc ForkControl(google.protobuf.DoubleValue) returns (device.proto.model.common.Nothing) {}
}