grpc模块调试
This commit is contained in:
parent
48a222ee31
commit
9889059f53
@ -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>
|
||||
|
@ -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());
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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>
|
||||
|
@ -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;
|
||||
}
|
@ -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;
|
||||
}
|
@ -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;
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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) {}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user