小工具      在线工具  汉语词典  dos游戏  css  js  c++  java

gRPC远程调用服务端与客户端连接详解

微服务,golang,rpc 额外说明

收录于:17天前

proto插件生成文件

参考之前的文章构建一个grpc实例,初步认识gprcgRPC 教程和应用

首先早gprc中下载了protoc插件,然后编写了.proto配置文件,通过插件生成了xxx.pb.goxxx_gprc.pb.go两个文件。前者是rpc服务器请求和响应参数的定义,后者是服务方法的定义包含构建服务器实例。

syntax = "proto3";

//编译为对应语言
//option java_package = "io.grpc.examples";
option go_package = "./;protoInterface";

package protoInterface;

// 定义接口
service Interface {
    
  // 方法1
  rpc GetProduct (Request) returns (Response) {
    }
  // 方法2
  rpc Util (Request) returns (Response) {
    }

}

// 定义数据类型
message Request {
    
  string paramString = 1;
}

//
message Response {
    
  string messageString = 1;
}

参数文件

在上述proto文件中,service定义了一个接口包含GetProductUtil两个方法,message定义了两个结构体参数Request请求参数和Response响应参数。

message定义的参数会生成在xxx.pb.go文件中,如下代码:

// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.28.1
// protoc v3.20.1
// source: build.proto

package protoInterface

import (
	protoreflect "google.golang.org/protobuf/reflect/protoreflect"
	protoimpl "google.golang.org/protobuf/runtime/protoimpl"
	reflect "reflect"
	sync "sync"
)

const (
	// Verify that this generated code is sufficiently up-to-date.
	_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
	// Verify that runtime/protoimpl is sufficiently up-to-date.
	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)

// 定义数据类型
type Request struct {
    
	state         protoimpl.MessageState
	sizeCache     protoimpl.SizeCache
	unknownFields protoimpl.UnknownFields

	ParamString string `protobuf:"bytes,1,opt,name=paramString,proto3" json:"paramString,omitempty"`
}

func (x *Request) Reset() {
    
	*x = Request{
    }
	if protoimpl.UnsafeEnabled {
    
		mi := &file_build_proto_msgTypes[0]
		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
		ms.StoreMessageInfo(mi)
	}
}

func (x *Request) String() string {
    
	return protoimpl.X.MessageStringOf(x)
}

func (*Request) ProtoMessage() {
    }

func (x *Request) ProtoReflect() protoreflect.Message {
    
	mi := &file_build_proto_msgTypes[0]
	if protoimpl.UnsafeEnabled && x != nil {
    
		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
		if ms.LoadMessageInfo() == nil {
    
			ms.StoreMessageInfo(mi)
		}
		return ms
	}
	return mi.MessageOf(x)
}

// Deprecated: Use Request.ProtoReflect.Descriptor instead.
func (*Request) Descriptor() ([]byte, []int) {
    
	return file_build_proto_rawDescGZIP(), []int{
    0}
}

func (x *Request) GetParamString() string {
    
	if x != nil {
    
		return x.ParamString
	}
	return ""
}

type Response struct {
    
	state         protoimpl.MessageState
	sizeCache     protoimpl.SizeCache
	unknownFields protoimpl.UnknownFields

	MessageString string `protobuf:"bytes,1,opt,name=messageString,proto3" json:"messageString,omitempty"`
}

func (x *Response) Reset() {
    
	*x = Response{
    }
	if protoimpl.UnsafeEnabled {
    
		mi := &file_build_proto_msgTypes[1]
		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
		ms.StoreMessageInfo(mi)
	}
}

func (x *Response) String() string {
    
	return protoimpl.X.MessageStringOf(x)
}

func (*Response) ProtoMessage() {
    }

func (x *Response) ProtoReflect() protoreflect.Message {
    
	mi := &file_build_proto_msgTypes[1]
	if protoimpl.UnsafeEnabled && x != nil {
    
		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
		if ms.LoadMessageInfo() == nil {
    
			ms.StoreMessageInfo(mi)
		}
		return ms
	}
	return mi.MessageOf(x)
}

// Deprecated: Use Response.ProtoReflect.Descriptor instead.
func (*Response) Descriptor() ([]byte, []int) {
    
	return file_build_proto_rawDescGZIP(), []int{
    1}
}

func (x *Response) GetMessageString() string {
    
	if x != nil {
    
		return x.MessageString
	}
	return ""
}

var File_build_proto protoreflect.FileDescriptor

var file_build_proto_rawDesc = []byte{
    
	0x0a, 0x0b, 0x62, 0x75, 0x69, 0x6c, 0x64, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0e, 0x70,
	0x72, 0x6f, 0x74, 0x6f, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x22, 0x2b, 0x0a,
	0x07, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x20, 0x0a, 0x0b, 0x70, 0x61, 0x72, 0x61,
	0x6d, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x70,
	0x61, 0x72, 0x61, 0x6d, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x22, 0x30, 0x0a, 0x08, 0x52, 0x65,
	0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x24, 0x0a, 0x0d, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67,
	0x65, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x6d,
	0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x32, 0x8f, 0x01, 0x0a,
	0x09, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x12, 0x41, 0x0a, 0x0a, 0x47, 0x65,
	0x74, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x12, 0x17, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f,
	0x49, 0x6e, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x2e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73,
	0x74, 0x1a, 0x18, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x66, 0x61,
	0x63, 0x65, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x3f, 0x0a,
	0x08, 0x47, 0x65, 0x74, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x17, 0x2e, 0x70, 0x72, 0x6f, 0x74,
	0x6f, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x2e, 0x52, 0x65, 0x71, 0x75, 0x65,
	0x73, 0x74, 0x1a, 0x18, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x66,
	0x61, 0x63, 0x65, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x13,
	0x5a, 0x11, 0x2e, 0x2f, 0x3b, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x66,
	0x61, 0x63, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}

var (
	file_build_proto_rawDescOnce sync.Once
	file_build_proto_rawDescData = file_build_proto_rawDesc
)

func file_build_proto_rawDescGZIP() []byte {
    
	file_build_proto_rawDescOnce.Do(func() {
    
		file_build_proto_rawDescData = protoimpl.X.CompressGZIP(file_build_proto_rawDescData)
	})
	return file_build_proto_rawDescData
}

var file_build_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
var file_build_proto_goTypes = []interface{
    }{
    
	(*Request)(nil),  // 0: protoInterface.Request
	(*Response)(nil), // 1: protoInterface.Response
}
var file_build_proto_depIdxs = []int32{
    
	0, // 0: protoInterface.Interface.GetProduct:input_type -> protoInterface.Request
	0, // 1: protoInterface.Interface.Util:input_type -> protoInterface.Request
	1, // 2: protoInterface.Interface.GetProduct:output_type -> protoInterface.Response
	1, // 3: protoInterface.Interface.Util:output_type -> protoInterface.Response
	2, // [2:4] is the sub-list for method output_type
	0, // [0:2] is the sub-list for method input_type
	0, // [0:0] is the sub-list for extension type_name
	0, // [0:0] is the sub-list for extension extendee
	0, // [0:0] is the sub-list for field type_name
}

func init() {
     file_build_proto_init() }
func file_build_proto_init() {
    
	if File_build_proto != nil {
    
		return
	}
	if !protoimpl.UnsafeEnabled {
    
		file_build_proto_msgTypes[0].Exporter = func(v interface{
    }, i int) interface{
    } {
    
			switch v := v.(*Request); i {
    
			case 0:
				return &v.state
			case 1:
				return &v.sizeCache
			case 2:
				return &v.unknownFields
			default:
				return nil
			}
		}
		file_build_proto_msgTypes[1].Exporter = func(v interface{
    }, i int) interface{
    } {
    
			switch v := v.(*Response); i {
    
			case 0:
				return &v.state
			case 1:
				return &v.sizeCache
			case 2:
				return &v.unknownFields
			default:
				return nil
			}
		}
	}
	type x struct{
    }
	out := protoimpl.TypeBuilder{
    
		File: protoimpl.DescBuilder{
    
			GoPackagePath: reflect.TypeOf(x{
    }).PkgPath(),
			RawDescriptor: file_build_proto_rawDesc,
			NumEnums:      0,
			NumMessages:   2,
			NumExtensions: 0,
			NumServices:   1,
		},
		GoTypes:           file_build_proto_goTypes,
		DependencyIndexes: file_build_proto_depIdxs,
		MessageInfos:      file_build_proto_msgTypes,
	}.Build()
	File_build_proto = out.File
	file_build_proto_rawDesc = nil
	file_build_proto_goTypes = nil
	file_build_proto_depIdxs = nil
}


产生了大量的大内容。这里我们主要看一下如何从请求中获取参数并将数据返回到响应体中。核心代码如下:

// 定义数据类型
type Request struct {
    
	state         protoimpl.MessageState
	sizeCache     protoimpl.SizeCache
	unknownFields protoimpl.UnknownFields

	ParamString string `protobuf:"bytes,1,opt,name=paramString,proto3" json:"paramString,omitempty"`
}

func (x *Request) GetParamString() string {
    
	if x != nil {
    
		return x.ParamString
	}
	return ""
}

type Response struct {
    
	state         protoimpl.MessageState
	sizeCache     protoimpl.SizeCache
	unknownFields protoimpl.UnknownFields

	MessageString string `protobuf:"bytes,1,opt,name=messageString,proto3" json:"messageString,omitempty"`
}

func (x *Response) GetMessageString() string {
    
	if x != nil {
    
		return x.MessageString
	}
	return ""
}

上述代码实现了从请求体中获取请求参数并设置响应体数据。

HTTP传输的是字符串,到了TCP层以二进制传输。
对于使用HTTP协议传输图片、文件,则有一个将二进制通过Base64等编码方式转换为字符串的过程。

HTTP传输的基本单位是文本数据,是字符流,因此需要序列化和反序列化过程。大多数框架会自动完成此步骤,只需要返回结构数据。

方法文件

方法文件中包含了构建rpc服务器与客户端实例的方法,以及相关的api用于获取服务端方法,客户端接受服务器端返回值的方法。方法文件一般都以XXX_grpc.pb.go命名。

//源码
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.2.0
// - protoc v3.20.1
// source: build.proto

package protoInterface

import (
	context "context"
	grpc "google.golang.org/grpc"
	codes "google.golang.org/grpc/codes"
	status "google.golang.org/grpc/status"
)

// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
// Requires gRPC-Go v1.32.0 or later.
const _ = grpc.SupportPackageIsVersion7

// InterfaceClient is the client API for Interface service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
type InterfaceClient interface {
    
	// 方法1
	GetProduct(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error)
	// 方法2
	Util(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error)
}

type interfaceClient struct {
    
	cc grpc.ClientConnInterface
}

func NewInterfaceClient(cc grpc.ClientConnInterface) InterfaceClient {
    
	return &interfaceClient{
    cc}
}

func (c *interfaceClient) GetProduct(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error) {
    
	out := new(Response)
	err := c.cc.Invoke(ctx, "/protoInterface.Interface/GetProduct", in, out, opts...)
	if err != nil {
    
		return nil, err
	}
	return out, nil
}

func (c *interfaceClient) Util(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error) {
    
	out := new(Response)
	err := c.cc.Invoke(ctx, "/protoInterface.Interface/Util", in, out, opts...)
	if err != nil {
    
		return nil, err
	}
	return out, nil
}

// InterfaceServer is the server API for Interface service.
// All implementations must embed UnimplementedInterfaceServer
// for forward compatibility
type InterfaceServer interface {
    
	// 方法1
	GetProduct(context.Context, *Request) (*Response, error)
	// 方法2
	Util(context.Context, *Request) (*Response, error)
	mustEmbedUnimplementedInterfaceServer()
}

// UnimplementedInterfaceServer must be embedded to have forward compatible implementations.
type UnimplementedInterfaceServer struct {
    
}

func (UnimplementedInterfaceServer) GetProduct(context.Context, *Request) (*Response, error) {
    
	return nil, status.Errorf(codes.Unimplemented, "method GetProduct not implemented")
}
func (UnimplementedInterfaceServer) Util(context.Context, *Request) (*Response, error) {
    
	return nil, status.Errorf(codes.Unimplemented, "method Util not implemented")
}
func (UnimplementedInterfaceServer) mustEmbedUnimplementedInterfaceServer() {
    }

// UnsafeInterfaceServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to InterfaceServer will
// result in compilation errors.
type UnsafeInterfaceServer interface {
    
	mustEmbedUnimplementedInterfaceServer()
}

func RegisterInterfaceServer(s grpc.ServiceRegistrar, srv InterfaceServer) {
    
	s.RegisterService(&Interface_ServiceDesc, srv)
}

func _Interface_GetProduct_Handler(srv interface{
    }, ctx context.Context, dec func(interface{
    }) error, interceptor grpc.UnaryServerInterceptor) (interface{
    }, error) {
    
	in := new(Request)
	if err := dec(in); err != nil {
    
		return nil, err
	}
	if interceptor == nil {
    
		return srv.(InterfaceServer).GetProduct(ctx, in)
	}
	info := &grpc.UnaryServerInfo{
    
		Server:     srv,
		FullMethod: "/protoInterface.Interface/GetProduct",
	}
	handler := func(ctx context.Context, req interface{
    }) (interface{
    }, error) {
    
		return srv.(InterfaceServer).GetProduct(ctx, req.(*Request))
	}
	return interceptor(ctx, in, info, handler)
}

func _Interface_Util_Handler(srv interface{
    }, ctx context.Context, dec func(interface{
    }) error, interceptor grpc.UnaryServerInterceptor) (interface{
    }, error) {
    
	in := new(Request)
	if err := dec(in); err != nil {
    
		return nil, err
	}
	if interceptor == nil {
    
		return srv.(InterfaceServer).Util(ctx, in)
	}
	info := &grpc.UnaryServerInfo{
    
		Server:     srv,
		FullMethod: "/protoInterface.Interface/Util",
	}
	handler := func(ctx context.Context, req interface{
    }) (interface{
    }, error) {
    
		return srv.(InterfaceServer).Util(ctx, req.(*Request))
	}
	return interceptor(ctx, in, info, handler)
}

// Interface_ServiceDesc is the grpc.ServiceDesc for Interface service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
var Interface_ServiceDesc = grpc.ServiceDesc{
    
	ServiceName: "protoInterface.Interface",
	HandlerType: (*InterfaceServer)(nil),
	Methods: []grpc.MethodDesc{
    
		{
    
			MethodName: "GetProduct",
			Handler:    _Interface_GetProduct_Handler,
		},
		{
    
			MethodName: "Util",
			Handler:    _Interface_Util_Handler,
		},
	},
	Streams:  []grpc.StreamDesc{
    },
	Metadata: "build.proto",
}

同样,对于方法文件,只查看核心代码,用于构建rpc服务器,映射逻辑层接口的API,构建客户端接收服务器返回值的API。如下

type InterfaceClient interface {
    
	// 方法1
	GetProduct(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error)
	// 方法2
	Util(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error)
}

XXX_grpc.pb.go文件中一般是第一个结构体,如上述带代码是gprc接口,包含rpc服务端的所有方法。

type interfaceClient struct {
    
	cc grpc.ClientConnInterface
}

第二个结构体,如上面的代码所示,是一个rpc客户端连接对象,代表连接到服务的一个实例。该文件还提供了构造实例的方法,用于与服务器连接对象构建服务器接口,如下:

func NewInterfaceClient(cc grpc.ClientConnInterface) InterfaceClient {
    
	return &interfaceClient{
    cc}
}

通过该方法可以获取客户端的接口,并通过接口调用方法。另外,该方法是在服务器端注册的。这样,服务器注册和客户端调用实际上都是在rpc容器内部进行的。

该方法的配置文件中还有一个服务器实例,如下:

// InterfaceServer is the server API for Interface service.
// All implementations must embed UnimplementedInterfaceServer
// for forward compatibility
type InterfaceServer interface {
    
	// 方法1
	GetProduct(context.Context, *Request) (*Response, error)
	// 方法2
	Util(context.Context, *Request) (*Response, error)
	mustEmbedUnimplementedInterfaceServer()
}

// UnimplementedInterfaceServer must be embedded to have forward compatible implementations.
type UnimplementedInterfaceServer struct {
    
}

这些都是通过协议文件自动生成的,这意味着在通过插件生成的代码中,已经完成了从方法到对应语言的结构体或类等数据结构的生成。开发者需要通过生成的方法搭建一个服务端,将方法注册到服务端(需要根据逻辑重写该方法),然后创建客户端接口来调用该方法。

例如,在 makefile 中,从服务器对象构建服务器实例:

//自定义结构体继承生成的服务器类
// Server 实现服务类
type Server struct {
    
	protoInterface.UnimplementedInterfaceServer
}
//重写服务器端方法(继承自生成的_grpc.pb的服务器端方法)
// GetProduct
func (Server) GetProduct(context.Context, *protoInterface.Request) (*protoInterface.Response, error) {
    
	//获取程序中的返回值
	param := service.Product{
    }
	product := param.DefaultProduct()
	json := param.ToJSON(product)
	return &protoInterface.Response{
    
		MessageString: json,
	}, nil
}

服务器端和客户端都可以使用方法。客户端的作用是接受返回值,服务器端通过继承重写方法来完成一定的逻辑。这样所有的方法都存在于rpc容器中,服务端和客户端都使用rpc容器来调用方法,实现了跨语言的功能。

//构建服务器实例

// 运行服务
func main() {
    
	//基于tcp实现(为网络设置端口)
	listen, err := net.Listen("tcp", ":1099")
	if err != nil {
    
		fmt.Println("failed to listen", err)
	}
	//创建grpc服务
	server := grpc.NewServer()
	//注册自定义方法
	protoInterface.RegisterInterfaceServer(server, &Server{
    })
	//启动服务
	err = server.Serve(listen)
	if err != nil {
    
		fmt.Println("failed to serve", err)
		return
	}
}

rpc服务器grpc.NewServer(),将方法的接口注册到服务器中通过RegisterInterfaceServer方法,这也是代码生成的。至此重写的方法的接口都被注册到服务器中了。

那么如何测试是否注册成功,或者如何调用呢?

答案是构建一个客户端调用方法,需要注意的是客户端实例是通过生成文件的_grpc.pb.文件提供的方法构建实例的,也就是说任何能调用该文件的程序都可以生成客户端实例,显然也需要请求与响应参数,也需要pb文件。

pb_grpc.pb文件复制到新项目中,构建客户端实例的代码如下:

func main() {
    
	//配置连连接参数(无加密)
	dial, err := grpc.Dial("localhost:1099", grpc.WithTransportCredentials(insecure.NewCredentials()))
	if err != nil {
    
		println("failed grpc connect", err)
	}
	defer dial.Close()
	//创建客户端连接
	client := protoInterface.NewInterfaceClient(dial)
	//通过客户端调用方法
	res, err := client.GetProduct(context.Background(), &protoInterface.Request{
    
		ParamString: "hello",
	})
	if err != nil {
    
		println("failed grpc recive err", err)
	}
	//打印接受的字符
	fmt.Printf("%v\n", res)

	//获取带product结构体在反序列化
	param := service.Product{
    }
	product := param.ToSTRUCT(res.MessageString)
	fmt.Println(product)

}

NewInterfaceClient是_grpc.pb的方法构建了一个客户端实例,客户端方法接口的所有方法都是和服务器共有的,你们服务器重写的方法注册中,客户端就可以通过实例和方法名直接调用。

如下图所示,客户端的调用直接返回序列化数据。

在这里插入图片描述

. . .

相关推荐

额外说明

Flutter运行windows项目时报错Bad UTF-8编码(U+FFFD; REPLACMENT CHARACTER)

解决方案: 下载vswhere.exe,替换本地c盘目录下的这个exe即可解决 https://github.com/microsoft/vswhere/releases

额外说明

Ajax接收循环数据,给操作button,的相应类添加function函数

1.先在js中定义函数, function classClick() { $('#content').html('点击事件'); } 2.在循环体中的button中加入点击事件,代码就不详细写了。 for循环。。 <div class="

额外说明

Java中synchronized:特性、使用、锁机制与策略简析

目录 synchronized的特性 互斥性 可见性 可重入性 synchronized的使用方法 synchronized的锁机制 常见锁策略 乐观锁与悲观锁 重量级锁与轻量级锁 公平锁与非公平锁 可重入锁与不可重入锁 自旋锁 读写锁 synchron

额外说明

SpringMVC第十二阶段:SpringMVC 的文件上传

文件上传 文件上传在SpringMVC中如何实现: 1、准备一个文件上传的表单 2、导入文件上传需要的jar包 commons-fileupload-1.2.1.jar、commons-io-1.4.jar 3、配置文件上传解析器 CommonsMult

额外说明

guava 简介、中文文档、中英对照文档 下载

guava 文档 下载链接(含jar包、源码、pom) 组件名称 中文-文档-下载链接 中英对照-文档-下载链接 guava-11.0.2.jar guava-11.0.2-API文档-中文版.zip guava-11.0.2-API文档-中英对照版.z

额外说明

[JAVAee]线程池

目录 线程池的作用 线程池的使用 线程池的创建方式 线程池的解析 ①Executors与ThreadPoolExecutor  ②ThreadPoolExecutor线程池的构造方法 ③RejectedExecutionHandler线程池的拒绝策略 固

额外说明

【NOI篇】1.1编程基础之输入输出 01:Hello,World!

1.1编程基础之输入输出 01:Hello,World! 答案: #include "iostream" using namespace std; int main() { cout<<"Hello, World!"; } 答案不唯一…

额外说明

代码中 isEmpty 和 isBlank 的区别

isEmpty系列 StringUtils.isEmpty() 是否为空. 可以看到 " " 空格是会绕过这种空判断,因为是一个空格,并不是严格的空值,会导致 isEmpty(" ")=false tringUtils.isEmpty(null) = t

额外说明

关于过滤链设计的实践记录

关于过滤链设计的实践记录 一、背景 最近,在做一个API网关的小项目,提升Java基础及项目设计能力。对于一个网关来说,过滤链的设计是其核心的设计思想,简单做了一个该网关的过滤链的流程,如下。为了更好地去理解过滤链的设计,该篇文章从基础理论的责任链设计模

ads via 小工具