刚接触 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
我们有一个 Google Cloud Function,它尝试连接到位于 Compute Engine 实例上的 Redis 服务器。Compute Engine Redis 端口已打开,可以从我们的本地计算机连接到 Redis 服务器。尽管如此,当云函数尝试这样做时,它会收到以下错误:
Redis 连接到 35.xxx.xx.xx:6379 失败 - 在 Exports._exceptionWithHostPort (util.js:1043) 处的 Object.exports._errnoException (util.js:1020:11) 连接 ETIMEDOUT 35.xxx.xx.xx:6379 :20) 在 TCPConnectWrap.afterConnect [as oncomplete] (net.js:1105:14) 代码:'ETIMEDOUT',errno:'ETIMEDOUT',系统调用:'connect',地址:'35.xxx.xx.xx',端口:6379}
我们正在使用redis npm 包(Redis 节点客户端)进行连接,该包再次可以在我们的本地计算机上运行。
我们将 EC 服务器的 IP 传递给主机值,将身份验证密钥传递给密码值。这似乎又在本地起作用。
有任何想法吗?
我有一个 TypeScript 服务器尝试使用 Struct 读取 JSON 对象,但它似乎仅部分适用于包含“fields”键的对象,然后该对象需要一个对象作为值。尽管如此,Struct 应该适用于任何 JSON 对象。
使用 BloomRPC 我正在尝试以下消息:
{
"payload": {
"fields": {
"Hello": {
"whatever": 0
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
服务器读取:
{ fields: { Hello: {} } }
Run Code Online (Sandbox Code Playgroud)
如果我发送:
{
"payload": {
"anotherfield": {
"HelloWorld": {
"whatever": 0
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我在服务器上得到一个空对象。
简化的 protobuf 文件如下所示:
syntax = "proto3";
import "google/protobuf/struct.proto";
// The service definition.
service TestTicketService {
rpc UpdateTicket (UpdateTicketRequest) returns (UpdateTicketResponse);
}
// The request message containing the required ticket information.
message …
Run Code Online (Sandbox Code Playgroud) 客户端可调用Firebase函数失败,并显示“错误:由于格式不正确,无法读取数据。” 部署到us-central1以外的地区(尝试过欧洲西部和亚洲)。
服务器代码
exports.getName = functions.region('europe-west1').https.onCall((data, context) => {
return { name: "Testopoulos" };
});
Run Code Online (Sandbox Code Playgroud)
客户端代码(React Native Firebase)
const httpsCallableUserName = firebase.functions().httpsCallable('getName');
getUserName = () => {
httpsCallableUserName()
.then(({ data }) => {
console.log(data.name);
})
.catch(httpsError => {
console.log(httpsError);
})
}
Run Code Online (Sandbox Code Playgroud)
在文档中有一条注释说:“ [使用HTTP函数提供动态内容进行托管时,您必须使用us-central1”,但我只是将一个对象返回到我们的前端React Native客户端,而不是使用Firebase Hosting。我阅读了有关该地区的其他文章,但我认为情况并非如此。有任何想法吗?