用于安装的命令:
npm install -g grpc-工具
纱线添加全局 grpc-tools
尝试在 mac m1 BigSur 上安装 grpc-tools 时。我遇到了下面粘贴的错误:
npm ERR! code 1
npm ERR! path /Users/abdulmoiz_ahmer/.nvm/versions/node/v16.13.1/lib/node_modules/grpc-tools
npm ERR! command failed
npm ERR! command sh -c node-pre-gyp install
npm ERR! response status 404 Not Found on https://node-precompiled-binaries.grpc.io/grpc-tools/v1.11.2/darwin-arm64.tar.gz
npm ERR! node-pre-gyp info it worked if it ends with ok
npm ERR! node-pre-gyp info using node-pre-gyp@1.0.8
npm ERR! node-pre-gyp info using node@16.13.1 | darwin | arm64
npm ERR! node-pre-gyp info check checked for "/Users/abdulmoiz_ahmer/.nvm/versions/node/v16.13.1/lib/node_modules/grpc-tools/bin/grpc_tools.node" (not found)
npm …Run Code Online (Sandbox Code Playgroud) 我正在 Node.JS 中实现的服务之间进行负载测试,同一台机器上的两个服务都通过localhost.
有 REST 和 gRPC 客户端和服务器文件。主要目标是证明 gRPC 比 HTTP 调用更快,因为使用 HTTP/2、使用比编码/解码 JSON 更高效的协议缓冲区......
但在我的测试中(发送整数数组)gRPC 慢得多。
对于这两种实现来说,代码都非常简单,我有一个辅助类来生成大小为(以 MB 为单位)的对象:0.125、0.25、0.5、1、2、5、20。REST 和 gRPC 服务器使用此辅助类,因此对象发送是一样的。
有效负载中发送的对象如下所示:
{
message: "Hello world",
array: []
}
Run Code Online (Sandbox Code Playgroud)
数组中填充数字,直到达到所需的大小。
我的 .proto 是这样的:
syntax = "proto3";
service ExampleService {
rpc GetExample (Size) returns (Example) {}
}
message Size {
int32 size = 1;
}
message Example {
string message = 1;
repeated int32 array = 2;
}
Run Code Online (Sandbox Code Playgroud)
另外,我运行的应用程序仅测量一次调用,不创建循环并查找平均值,也不用回调处理测量时间。所以我运行该应用程序 10 次并计算平均值。
休息服务器:
app.get('/:size',(req,res) => {
const size …Run Code Online (Sandbox Code Playgroud) 我们公司已使用Firestore构建了一个电子应用程序,现在我们正尝试将该应用程序部署在公司代理和防火墙(客户环境)之后。在使用电子设置代理身份验证设置之后app.on('login'),除firestore连接外,应用程序中的所有网络请求均成功。
我们收到以下错误:
[2018-09-21T09:09:13.556Z] @firebase/firestore: Firestore (5.5.0) [Connection]: GRPC stream error. Code: 14 Message: 14 UNAVAILABLE: Connect Failed
[2018-09-21T09:09:13.557Z] @firebase/firestore: Firestore (5.5.0) [PersistentStream]: close with error: FirebaseError: [code=unavailable]: 14 UNAVAILABLE: Connect Failed
[2018-09-21T09:09:13.557Z] @firebase/firestore: Firestore (5.5.0): Could not reach Cloud Firestore backend. Connection failed 1 times. Most recent error: FirebaseError: [code=unavailable]: 14 UNAVAILABLE: Connect Failed
This typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until …Run Code Online (Sandbox Code Playgroud) 请参阅https://github.com/grpc/grpc-node/issues/1202。
通常在CRUD操作中,不提供值意味着不更改该字段,空数组[]意味着清除该字段内的所有项目。
但如果你试图实现CRUD操作并通过grpc将其作为服务提供,那么上述场景就很难实现。
service CRUD {
rpc updateTable(updateRequest) returns updateResponse {}
}
message updateRequest {
repeated string a = 1;
string b = 2;
}
message updateResponse {
boolean success = 1;
}
Run Code Online (Sandbox Code Playgroud)
如果您使用默认选项加载包,则客户端无法删除 by 的项目
client.CRUD.updateTable({a: []})
Run Code Online (Sandbox Code Playgroud)
因为参数到达服务器端时{a: []}就变成了。{}
如果您使用选项 {arrays: true} 加载包,则该字段a将被无意中清除,而客户端仅尝试更新其他字段:
client.CRUD.updateTable({b: 'updated value'})
Run Code Online (Sandbox Code Playgroud)
因为参数到达服务器端时{b: 'updated value'}就变成了。{a: [], b: 'updated value'}
任何人都可以分享一些关于如何使用grpc-node和 处理这两种情况的更好的想法吗proto3?
我读过这个答案:/sf/answers/3986064001/,它说无法使用grpc-nodepackage.json 在相同的地址和端口运行 gRPC 服务器和 HTTP 服务器。
但我可以使用 package.json 在相同的地址和端口(例如都使用localhost:3000)创建 gRPC 服务器和 HTTP 服务器grpc-go。这是一个示例: https: //github.com/mrdulin/grpc-go-cnode/blob/master/cmd/server/main.go#L79
那么,为什么 grpc-node 和 grpc-go 的行为不一致。这有道理吗?
我期望的结果是,无论grpc中实现什么语言,行为都应该是一致的。所以grpc服务器应该能够与同一系统进程中的Node标准库http创建的服务器共享相同的端口。
我正在尝试将protoc命令运行到 docker 容器中。
我尝试使用gRPC 映像,但未protoc找到命令:
/bin/sh: 1: 协议:未找到
所以我假设我必须使用RUN说明手动安装,但是有更好的解决方案吗?已安装官方预编译映像protoc?
另外,我尝试通过 Dockerfile 安装,但又出现了protoc: not found。
这是我的 Dockerfile
#I'm not using "FROM grpc/node" because that image can't unzip
FROM node:12
...
# Download proto zip
ENV PROTOC_ZIP=protoc-3.14.0-linux-x86_32.zip
RUN curl -OL https://github.com/protocolbuffers/protobuf/releases/download/v3.14.0/${PROTOC_ZIP}
RUN unzip -o ${PROTOC_ZIP} -d ./proto
RUN chmod 755 -R ./proto/bin
ENV BASE=/usr/local
# Copy into path
RUN cp ./proto/bin/protoc ${BASE}/bin
RUN cp -R ./proto/include/* ${BASE}/include
RUN protoc -I=... …Run Code Online (Sandbox Code Playgroud) 刚接触 Google Cloud Run 并尝试让两个 node.js 微服务通过 gRPC 进行内部通信。
客户端界面:
constructor(address: string, credentials: grpc.ChannelCredentials, options?: object);
Run Code Online (Sandbox Code Playgroud)
客户端代码:
const client: MyClient = new MyClient('my-service-abcdefgh3a-ew.a.run.app:443', grpc.credentials.createSsl());
Run Code Online (Sandbox Code Playgroud)
服务器代码:
const server = new grpc.Server();
server.addService<IMyServer>(MyService, new MyServer());
server.bind(`0.0.0.0:${process.env.PORT}`, grpc.ServerCredentials.createInsecure());
server.start();
Run Code Online (Sandbox Code Playgroud)
服务器设置为侦听 443。
当服务对公共请求开放时,上述内容似乎有效,但当您将服务器设置为内部时则无效。有任何想法吗?
node.js google-cloud-platform grpc grpc-node google-cloud-run
我尝试使用下面的代码测试我的 grpc 客户端连接。我有 .net core grpc 服务器并使用 Node js grpc 客户端进行连接。但出现“无法连接到所有地址”错误。但能够将 .net grpc 服务器连接到 .net grpc 客户端。非常感谢任何帮助。
不确定我是否遗漏了下面 grpc 客户端代码中的任何内容。
'use strict';
//Same as the other projects we import fs for reading documents, in this case employees.js json
const fs = require('fs');
//Importing GRPC and the proto loader
const grpc = require('grpc');
const loader = require('@grpc/proto-loader');
//reads the proto
const packageDefinition = loader.loadSync('Repository.proto', {
keepCase: false,
longs: String,
enums: String,
defaults: true,
oneofs: true
});
//Loads the proto file to …Run Code Online (Sandbox Code Playgroud) 如果我有一个 proto3 消息定义如下
message Log {
string object = 1;
string key_result = 2;
string review = 3;
repeated string tag = 4;
string begin_at = 5;
string end_at = 6;
string created_at = 7;
string id = 8;
}
Run Code Online (Sandbox Code Playgroud)
withprotoc 和将--js_out生成--ts_outdts 类似
export class Log extends jspb.Message {
getObject(): string;
setObject(value: string): void;
getKeyResult(): string;
setKeyResult(value: string): void;
getReview(): string;
setReview(value: string): void;
clearTagList(): void;
getTagList(): Array<string>;
setTagList(value: Array<string>): void;
addTag(value: string, index?: number): …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个基于 Node/Express 的 REST 服务器。如何在同一个 REST 服务器中添加 GRPC 服务器,或者它必须是完全不同的仅托管 GRPC 服务器的 NodeJS 服务器。