GRPC-go版本
GRPC-go版本
1.安装GO,protobuf
只适合有梯子的
GO的安装没必要说了
protobuf :https://github.com/protocolbuffers/protobuf/releases
选合适的版本,将解压后bin目录的protoc.exe放到GO的安装目录的bin下(省事)

打开CMD,输入protoc --version,正常如下图

环境变量有三个需要设置
GOPATH:是GO的工程目录
GOBIN:生成的exe目录
PATH:电脑环境变量


2.安装相关包
2021-0721
好像要在grpcTest目录下,go mod init 之后进行安装,也有可能是我电脑问题,
1.golang 的proto工具包
go get -u github.com/golang/protobuf/proto
2.golang 的proto编译支持
go get -u github.com/golang/protobuf/protoc-gen-go
3.安装grpc包
go get -u google.golang.org/grpc
4.安装grpc-gen插件
go get -u google.golang.org/protobuf/cmd/protoc-gen-go
go install google.golang.org/protobuf/cmd/protoc-gen-go
go get -u google.golang.org/grpc/cmd/protoc-gen-go-grpc
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc
安装正常的话,在GOPATH的bin目录下会有两个exe

3.检验
去下载示例代码,放到GOPATH下,找到里面的helloworld
git clone -b v1.35.0 https://github.com/grpc/grpc-go
在GOPATH下新建grpcTest,项目结构如下

helloworld.proto(官方)
// Copyright 2015 gRPC authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
syntax = "proto3";
option go_package = "google.golang.org/grpc/examples/helloworld/helloworld";
-->换成option go_package="." 表示生成的proto.go在当前目录
option java_multiple_files = true;
option java_package = "io.grpc.examples.helloworld";
option java_outer_classname = "HelloWorldProto";
package helloworld;
// The greeting service definition.
service Greeter {
// 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;
}
生成.go文件

client.go(官方) server和client一样,我这就只列举client
/*
*
* Copyright 2015 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
// Package main implements a client for Greeter service.
package main
import (
"context"
"log"
"os"
"time"
"google.golang.org/grpc"
pb "google.golang.org/grpc/examples/helloworld/helloworld"
--》改成 pb "grpcTest/proto"
)
const (
address = "localhost:50051"
defaultName = "world"
)
func main() {
// Set up a connection to the server.
conn, err := grpc.Dial(address, grpc.WithInsecure(), grpc.WithBlock())
if err != nil {
log.Fatalf("did not connect: %v", err)
}
defer conn.Close()
c := pb.NewGreeterClient(conn)
// Contact the server and print out its response.
name := defaultName
if len(os.Args) > 1 {
name = os.Args[1]
}
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
r, err := c.SayHello(ctx, &pb.HelloRequest{Name: name})
if err != nil {
log.Fatalf("could not greet: %v", err)
}
log.Printf("Greeting: %s", r.GetMessage())
}
然后去运行sever和client

ok了
还是建议大家多去看官方的介绍,不要怕英文,有点底子的都能看懂
出现protoc-gen-go' is not recognized as***********就是你没配置好环境变量,把GOPATH下的bin加到PATH里去
参考链接
- Quick start | Go | gRPC
- Go gRPC教程-环境安装(一) - 烟花易冷人憔悴 - 博客园 (cnblogs.com)
- (5条消息) 完美解决:protoc-gen-go-grpc: program not found or is not executable_李纳克斯的博客-CSDN博客
GRPC-go版本的更多相关文章
- 编译gRPC Go版本使用的 ProtoBuffer 文件
本篇文章主要解决mac下安装ProtoBuffer,编译go版本gRPC用的.proto文件 安装 protoc 注意,gRPC 需要用到 proto3, 而目前 Release 的版本是 2.6.1 ...
- .net core grpc 实现通信(一)
现在系统都服务化,.net core 实现服务化的方式有很多,我们通过grpc实现客户端.服务端通信. grpc(https://grpc.io/)是google发布的一个开源.高性能.通用RPC(R ...
- .net core grpc consul 实现服务注册 服务发现 负载均衡(二)
在上一篇 .net core grpc 实现通信(一) 中,我们实现的grpc通信在.net core中的可行性,但要在微服务中真正使用,还缺少 服务注册,服务发现及负载均衡等,本篇我们将在 .net ...
- gRPC入坑记
概要 由于gRPC主要是谷歌开发的,由于一些已知的原因,gRPC跑demo还是不那么顺利的.单独写这一篇,主要是gRPC安装过程中的坑太多了,记录下来让大家少走弯路. 主要的坑: 如果使用PHP.Py ...
- 使用grpc C++功能
grpc c++开发需要安装相关工具以及框架才能进行开发. rz 远程上传文件 本地开发环境搭建: 1.编译相关工具 pkg-config autoconf automake Libtool shto ...
- .Net Core Grpc Consul 实现服务注册 服务发现 负载均衡
本文是基于..net core grpc consul 实现服务注册 服务发现 负载均衡(二)的,很多内容是直接复制过来的,..net core grpc consul 实现服务注册 服务发现 负载均 ...
- .Net Core Grpc 实现通信
.Net Core 3.0已经把Grpc作为一个默认的模板引入,所以我认为每一个.Net程序员都有学习Grpc的必要,当然这不是必须的. 我在我的前一篇文章中介绍并创建了一个.Net Core 3.0 ...
- RPC详解
RPC(Remote Procedure Call),即远程过程调用,是一个分布式系统间通信的必备技术,本文体系性地介绍了 RPC 包含的核心概念和技术,希望读者读完文章,一提到 RPC,脑中不是零碎 ...
- 理解REST和RPC
REST 越来越多的人开始意识到,网站即软件,而且是一种新型的软件. 网站开发,完全可以采用软件开发的模式.但是传统上,软件和网络是两个不同的领域,很少有交集:软件开发主要针对单机环境,网络则主要研究 ...
- .net core consul grpc--系统服务RPC实现通信(一)
.net core grpc 系统服务实现通信(一) 现在系统都服务化,.net core 实现服务化的方式有很多,我们通过grpc实现客户端.服务端通信. grpc(https://grpc.io/ ...
随机推荐
- vue项目部署到阿里云服务器(windows),Nginx代理!
项目构成: 前端:vue+vant-ui, 数据库:mysql, 后端:node.js 部署方式:nginx代理: 一,首先要拥有自己的服务器,阿里,腾讯都可以,我用的是阿里的: 如果只是做个人项目的 ...
- 说说如何安装 Openfire
Openfire 是一个基于 XMPP 协议的 IM 服务框架.这里我们来说一说如何安装它. 1 下载 zip 安装包 首先下载 Openfire 安装包,下载路径为:http://www.ignit ...
- 关于深搜dps
哈哈,我又来了! 但是!今天我又带来了让人开心到窒息的 ----深搜dps 其实关于深搜,概念没啥可讲的,总结一句话概括就是:一直往下搜,直到满足条件的,再回来,沿着下一条路搜,直到把路全走完为止.. ...
- 阿里一面,说说你了解zookeeper的应用场景有哪些?
1.前言 又到了金三银四的时候,大家都按耐不住内心的躁动,我在这里给大家分享下之前面试中遇到的一个知识点(zookeeper应用场景),希望对大家有些帮助.如有不足,欢迎大佬们指点指点. 2.zook ...
- 仿真pda,部署时出现问题
为什么部署到基于 Windows Mobile 的 Pocket PC 设备或模拟器会因共享冲突错误而失败 自己遇到了网上找到的解决方案http://hi.baidu.com/yeflower/blo ...
- USB接口定义 | USB Type C接口定义 | 制作Type A转Type C充电-数据线
1. USB接口定义 2. USB Type C接口定义 Type C接口母头(插座) Type C接口公头(插头) 引脚定义 参考:https://www.cnblogs.com/zhouhaoch ...
- Kerberos基本原理、安装部署及用法
1. 概述 Kerberos是一种认证机制. 目的是,通过密钥系统为客户端/服务器应用程序提供强大的认证系统:保护服务器防止错误的用户使用,同时保护它的用户使用正确的服务器,即支持双向验证:Kerbe ...
- 面试问题之C++语言:简述编译过程
转载于:https://blog.csdn.net/ypshowm/article/details/89374706 编译过程主要分为四步: 1.词法分析(扫描) 运行类似于有限状态机的算法将源代码的 ...
- 用TLS/SSL保证EMQ的网络传输安全
作为基于现代密码学公钥算法的安全协议,TLS/SSL能在计算机通讯网络上保证传输安全,EMQ的MQTT broker支持TLS,也可以用这种方式来确保传输安全. 参考官网:https://www.em ...
- java后端使用token处理表单重复提交
保证接口幂等性,表单重复提交 前台解决方案:提交后按钮禁用.置灰.页面出现遮罩后台解决方案: 使用token,每个token只能使用一次1.在调用接口之前生成对应的Token,存放至redis 2 ...