备注:

 elixir  grpc 封装测试
 
1.  安装
a. 安装 protoc 参考相关文档,比较简单
b. 安装elixir grpc 插件 protoc-gen-elixir 同时配置环境变量
 
2. 基本项目使用
a. 创建项目
mix new appdemo cd appdemo touch helloword.proto syntax = "proto3"; option java_multiple_files = true;
option java_package = "io.grpc.examples.helloworld";
option java_outer_classname = "HelloWorldProto";
option objc_class_prefix = "HLW"; 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;
} 项目结构如下: ├── README.md
├── config
│ └── config.exs
├── helloword.proto
├── lib
│ ├── appdemo.ex
├── mix.exs
└── test
├── appdemo_test.exs
└── test_helper.exs b. 生成代码 protoc --elixir_out=./lib helloword.proto
protoc -I . --elixir_out=plugins=grpc:./lib/ helloword.proto
结果如下: ├── README.md
├── config
│ └── config.exs
├── helloword.proto
├── lib
│ ├── appdemo.ex
│ └── helloword.pb.ex
├── mix.exs
└── test
├── appdemo_test.exs
└── test_helper.exs 内容: defmodule Helloworld.HelloRequest do
use Protobuf @type t :: %__MODULE__{
name: String.t()
}
defstruct [:name] field :name, 1, optional: true, type: :string
end defmodule Helloworld.HelloReply do
use Protobuf @type t :: %__MODULE__{
message: String.t()
}
defstruct [:message] field :message, 1, optional: true, type: :string
end defmodule Helloworld.Greeter.Service do
use GRPC.Service, name: "helloworld.Greeter" rpc :SayHello, Helloworld.HelloRequest, Helloworld.HelloReply
end defmodule Helloworld.Greeter.Stub do
use GRPC.Stub, service: Helloworld.Greeter.Service
end
 
 
3. 项目使用(接上面项目)
a.  server端实现代码

lib/server.ex

defmodule Helloworld.Greeter.Server do
use GRPC.Server, service: Helloworld.Greeter.Service @spec say_hello(Helloworld.HelloRequest.t(), GRPC.Server.Stream.t()) ::
Helloworld.HelloReply.t()
def say_hello(request, _stream) do
Helloworld.HelloReply.new(message: "Hello #{request.name}")
end
end b. 项目使用opt 进行运行,具体来说是supervisor lib/helloworld_app.ex defmodule HelloworldApp do
use Application def start(_type, _args) do
import Supervisor.Spec children = [
supervisor(GRPC.Server.Supervisor, [{Helloworld.Greeter.Server, 50051}])
] opts = [strategy: :one_for_one, name: HelloworldApp]
Supervisor.start_link(children, opts)
end
end c. mix.exs 启动配置 def application do
[mod: {HelloworldApp, []},
applications: [:logger, :grpc]]
end defp deps do
[
{:grpc, github: "tony612/grpc-elixir"},
{:dialyxir, "~> 0.5", only: [:dev, :test], runtime: false},
]
end d. config/config.exs use Mix.Config # Start server in OTP
config :grpc, start_server: true
 
 
4. 启动
mix  deps.get,compile
iex -S mix
 
5. golang client demo 
 
参考 https://github.com/rongfengliang/grpc-elixir
 
 
6. 参考资料
https://github.com/rongfengliang/grpc-elixir
https://github.com/rongfengliang/gprc-elixir-server
https://github.com/tony612/grpc-elixir
 
 
 
 
 

elixir grpc 试用的更多相关文章

  1. nginx grpc 试用

    1. 编译 wget https://nginx.org/download/nginx-1.13.10.tar.gz tar xvf nginx-1.13.10.tar.gz cd nginx-1.1 ...

  2. RPC的故事

    今天我跟几个RPC框架之间发生了一些事,情节跌宕起伏一波三折,不吐不快,以至于我这个从来不写博客的人也忍不住写下来分享一下. 背景 主系统部署在Windows上(.NET 4.5),子系统(.NET ...

  3. phoenix elixir 框架简单试用

    备注:   官方提供的脚手架工具,我们可以直接使用,生成代码,同时需要nodejs 环境配置(比较简单,参考 相关资料即可)  1. 安装脚手架 mix archive.install https:/ ...

  4. purescript 基本试用

    安装环境 安装预编译文件 https://github.com/purescript/purescript/releases 配置环境变量: export PATH=$PATH:/Users/dalo ...

  5. 【译】gRPC vs HTTP APIs

    本文翻译自 ASP.NET Blog | gRPC vs HTTP APIs,作者 James,译者 Edison Zhou. 写在开头 现在,ASP.NET Core使开发人员可以构建gRPC服务. ...

  6. 「译」 .NET 6 中 gRPC 的新功能

    gRPC是一个现代的.跨平台的.高性能的 RPC 框架.gRPC for .NET 构建在 ASP.NET Core 之上,是我们推荐的在 .NET 中构建 RPC 服务的方法. .NET 6 进一步 ...

  7. 解决go-micro与其它gRPC框架之间的通信问题

    在之前的文章中分别介绍了使用gRPC官方插件和go-micro插件开发gRPC应用程序的方式,都能正常走通.不过当两者混合使用的时候,互相访问就成了问题.比如使用go-micro插件生成的gRPC客户 ...

  8. gRPC源码分析1-SSL/TLS

    引子 前几天看到微信后台团队分享了TLS相关文章,正好gRPC里TLS数据加密是很重要的一块,于是整理出了这篇文章. 在gRPC里,如果仅仅是用来做后端微服务,可以考虑不加密.本文太长,先给个大纲. ...

  9. gRPC源码分析2-Server的建立

    gRPC中,Server.Client共享的Class不是很多,所以我们可以单独的分别讲解Server和Client的源码. 通过第一篇,我们知道对于gRPC来说,建立Server是非常简单的,还记得 ...

随机推荐

  1. C++实现矩阵压缩

    C++实现矩阵压缩 转置运算时一种最简单的矩阵运算.对于一个m*n的矩阵M,他的转置矩阵T是一个n*m的矩阵,且T(i,j) = M(j,i). 一个稀疏矩阵的转置矩阵仍然是稀疏矩阵. 矩阵转置 方案 ...

  2. Linux命令详解-touch

    linux的touch命令不常用,一般在使用make的时候可能会用到,用来修改文件时间戳,或者新建一个不存在的文件. 1.命令格式: touch [选项]... 文件... 2.命令参数: -a 或- ...

  3. day28 CRM万能权限组件开发 && 主机管理-堡垒机

    1,CRM项目实战-万能权限组件开发参考博客:http://www.cnblogs.com/alex3714/articles/6661911.html 参考代码:https://github.com ...

  4. sql 日志统计-日、周、月活跃数

    近日网站需求:统计日志表的 日.周.月活跃数.最终研究了出来了,分享给大家看下.  如果有更好的sql语句也可以评论下方. --日活跃量 ), cr.AddTime, )as addtimt,COUN ...

  5. hdu 2818 Building Block(并查集,有点点复杂)

    Building Block Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  6. UI-基本控件的简单使用

    1.IBAction:   //====================== 1> 能保证方法可以连线 2> 相当于void 2.IBOutlet: 1> 能保证属性可以连线 3.常 ...

  7. PostgreSQL日志号LSN和wal日志文件简记

    弄明白日志号的原理之后,一段时间又有点忘记了,干脆整理一遍: (一)wal文件命名规则 1)在$PGDATA目录下面的pg_xlog目录中存放着xlog日志文件(10.1之后变为了pg_wal): t ...

  8. 主题模型︱几款新主题模型——SentenceLDA、CopulaLDA、TWE简析与实现

    百度最近开源了一个新的关于主题模型的项目.文档主题推断工具.语义匹配计算工具以及基于工业级语料训练的三种主题模型:Latent Dirichlet Allocation(LDA).SentenceLD ...

  9. 服务器重装和配置:Ubuntu16.04 + Anaconda3 + GTX1080驱动 + CUDA8 + cuDNN + 常用工具安装

    前一篇[基于Ubuntu16.04的GeForce GTX 1080驱动安装,遇到的问题及对应的解决方法]是在机器原有系统上安装GPU驱动,后来决定备份数据后重装系统,让服务器环境更干净清爽. 1.安 ...

  10. NSArray中的对象进行排序

    看在iOS中有哪些方法可以对NSArray中的对象进行排序.下面是目录: 小引 使用NSComparator进行排序 使用NSDescriptor进行排序 使用selector进行排序 小引 我们将要 ...