Registry / devops / adonis-grpc-consumer

adonis-grpc-consumer

JSON →
library0.1.2jsnpmunverified

Adonis gRPC Consumer is a provider for AdonisJS (v5) that simplifies communication with gRPC services. It integrates seamlessly with the Adonis framework, providing a declarative configuration for gRPC clients, automatic connection management, and TypeScript support. Version 0.1.2 is the latest stable release. Unlike generic gRPC clients, it leverages Adonis's IoC container and lifecycle, reducing boilerplate for defining and injecting gRPC service stubs. The package ships its own type definitions and uses @grpc/grpc-js and @grpc/proto-loader for gRPC connectivity.

npm install adonis-grpc-consumer
INSTALL
IMPORT
SIG · ADONIS-GRPC-CONSUM
A
adonis-grpc-consumer
devopsjavascriptv0.1.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

GrpcConsumer
import GrpcConsumer from '@ioc:Adonis/Addons/GrpcConsumer'
import { GrpcConsumer } from 'adonis-grpc-consumer'
The package is registered as an Adonis provider; you must use the IoC string @ioc:Adonis/Addons/GrpcConsumer for the default export. Named imports from the package directly won't work.
grpc
import GrpcConsumer, { grpc } from '@ioc:Adonis/Addons/GrpcConsumer'
const grpc = require('@grpc/grpc-js')
The grpc object is re-exported from the provider for convenience. Although @grpc/grpc-js is a dependency, the recommended import is from the IoC container to ensure compatibility.
GrpcConsumerConfig
import { GrpcConsumerConfig } from '@ioc:Adonis/Addons/GrpcConsumer'
import { GrpcConsumerConfig } from 'adonis-grpc-consumer'
Type imports also use the IoC path. The config type is used in config/grpc-consumer.ts.

Configures a gRPC client for an AdonisJS app and uses it to call a remote procedure with type safety.

// In config/grpc-consumer.ts import path from 'path' import { GrpcConsumerConfig } from '@ioc:Adonis/Addons/GrpcConsumer' const grpcConfig: GrpcConsumerConfig = { verbose: true, clients: [ { name: 'MY_SERVICE', options: { package: 'my_service', serviceName: 'MyService', protoPath: path.join(__dirname, '../proto/myService.proto'), url: '127.0.0.1:4545', }, }, ], } export default grpcConfig // In a controller or service import GrpcConsumer, { grpc } from '@ioc:Adonis/Addons/GrpcConsumer' import { MyServiceClient } from 'proto/my_service/MyService' const client = GrpcConsumer.getClient<MyServiceClient>('MY_SERVICE') client.SendMessage({ message: 'hello' }, (error?: grpc.ServiceError) => { if (error) { console.error(error.message) } })
Debug
Known issues
gotchaProto file path must be relative to the project root or absolute. Using path.join(__dirname, '../proto/...') is recommended.
fix
Ensure the protoPath in config is correct. For example: path.join(__dirname, '../proto/myService.proto').
affects: >=0.0.1
gotchaThe IoC string '@ioc:Adonis/Addons/GrpcConsumer' is case-sensitive. A typo will cause a runtime error.
fix
Double-check the import string: '@ioc:Adonis/Addons/GrpcConsumer' exactly.
affects: >=0.0.1
gotchaTypeScript definitions for protobuf must be generated manually using 'npx build-proto' before using the client.
fix
Run: npx build-proto --longs=String --enums=String --defaults --oneofs --grpcLib=@grpc/grpc-js --outDir=./proto/ ./proto/*.proto
affects: >=0.0.1
Errors
Common errors & fixes
Cannot find module '@ioc:Adonis/Addons/GrpcConsumer'
The provider is not installed or not registered in .adonisrc.json.
fix
Run 'node ace configure adonis-grpc-consumer' to register the provider.
GRPC Client MY_SERVICE connection failed: Error: 14 UNAVAILABLE: failed to connect to all addresses
The gRPC server is not running or the URL is incorrect.
fix
Verify the gRPC server is running and the URL in config/grpc-consumer.ts matches the server address.
Property 'SendMessage' does not exist on type 'GrpcClient<MyServiceClient>'
The generated proto types are missing or incorrectly linked.
fix
Regenerate TypeScript definitions using 'npx build-proto' and ensure the import path matches the generated file location.
Upgrade
Version history
0.1.2latest on npm
Audit
Dependencies
@grpc/grpc-jsrequiredgRPC implementation for Node.js, required for client connections.
@grpc/proto-loaderrequiredLoads .proto files and generates TypeScript definitions.
@adonisjs/corerequiredAdonisJS framework dependency, required for provider and IoC.
Agent activity
31 hits · last 30 days
node
28
OpenAI (training)
1
Resources
adonis-grpc-consumer — npm install adonis-grpc-consumer · libregistry