
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
@142vip/egg-grpc-client
Advanced tools
# npm
npm install @142vip/egg-grpc-client
# pnpm
pnpm i @142vip/egg-grpc-client
const { defaultPluginConfig } = require('@142vip/egg')
const { exampleProto, GrpcConnectURI } = require('@142vip/grpc')
const { name: pkgName } = require('../package.json')
module.exports = {
grpcClient: defaultPluginConfig(pkgName, {
client: {
connectUri: GrpcConnectURI.PORT_50001,
protoPaths: [exampleProto],
},
}),
}
const { exampleProto } = require('@142vip/egg-grpc-server/example/example-grpc')
const { GrpcConnectURI } = require('@142vip/grpc')
module.exports = {
grpcClient: {
client: {
connectUri: GrpcConnectURI.PORT_50003,
protoPaths: [exampleProto],
},
},
}
const { exampleProto } = require('@142vip/egg-grpc-server/example/example-grpc')
const { GrpcConnectURI } = require('@142vip/grpc')
module.exports = {
grpcClient: {
clients: {
example1: {
connectUri: GrpcConnectURI.PORT_50001,
protoPaths: [exampleProto],
},
example2: {
connectUri: GrpcConnectURI.PORT_50002,
protoPaths: [exampleProto],
},
},
},
}
// 获取grpc客户端
const grpcClient = this.app.grpcClient
// 单客户端配置,获取实例
const defaultInstance = grpcClient.getInstance('default')
// 多客户端配置,获取实例
const example1Instance = grpcClient.getInstance('example1')
const example2Instance = grpcClient.getInstance('example2')
const exampleService = example1Instance.getService(exampleProtoServicePath)
import { exampleProtoServicePath, GrpcExampleServiceMethod, sendGrpcRequest } from '@142vip/grpc'
// 调用ClientToServer方法,客户端非流式、服务端非流式
const response = await sendGrpcRequest(exampleServiceClient, GrpcExampleServiceMethod.ClientToServer, {
name: GrpcExampleServiceMethod.ClientToServer
})
console.log(`${GrpcExampleServiceMethod.ClientToServer} response===>`, response)
import { exampleProtoServicePath, GrpcExampleServiceMethod, sendGrpcRequest } from '@142vip/grpc'
// 调用ClientToServerStream方法,客户端非流式、服务端流式
const response = await sendGrpcRequest(exampleServiceClient, GrpcExampleServiceMethod.ClientToServerStream, {
name: GrpcExampleServiceMethod.ClientToServerStream
})
console.log(`${GrpcExampleServiceMethod.ClientToServerStream} response===>`, response)
import { exampleProtoServicePath, GrpcExampleServiceMethod, sendGrpcRequest } from '@142vip/grpc'
// 调用ClientStreamToServerStream方法,客户端流式、服务端流式
const response = await sendGrpcRequest(exampleServiceClient, GrpcExampleServiceMethod.ClientStreamToServerStream, {
name: GrpcExampleServiceMethod.ClientStreamToServerStream
})
console.log(`${GrpcExampleServiceMethod.ClientStreamToServerStream} response===>`, response)
import { exampleProtoServicePath, GrpcExampleServiceMethod, sendGrpcRequest } from '@142vip/grpc'
// 调用ClientStreamToServerStream方法,客户端流式、服务端流式
const response = await sendGrpcRequest(exampleServiceClient, GrpcExampleServiceMethod.ClientStreamToServerStream, {
name: GrpcExampleServiceMethod.ClientStreamToServerStream
})
console.log(`${GrpcExampleServiceMethod.ClientStreamToServerStream} response===>`, response)
基于sendGrpcRequest方法,可以很方面地实现GRPC的四种模式调用,同时支持async/await操作,在业务中可以直接使用try/catch捕获异常。
Copyright (c) 2019-present, @142vip 储凡
仅供学习参考,商业使用请保留作者版权信息,作者不保证也不承担任何软件的使用风险。
FAQs
Egg.js框架下使用grpc的插件,简化grpc客户端配置
We found that @142vip/egg-grpc-client demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.