new Client(address, credentials, options)
A generic gRPC client. Primarily useful as a base class for generated clients
Parameters:
| Name | Type | Description | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
address |
string | Server address to connect to |
||||||||||||||||||||||||
credentials |
grpc.credentials~ChannelCredentials | Credentials to use to connect to the server |
||||||||||||||||||||||||
options |
Object | Options to apply to channel creation. Any of the channel arguments can be used here in addition to specific client options. Properties
|
Methods
-
close()
-
Close this client.
-
getChannel()
-
Return the underlying channel object for the specified client
Returns:
The channel
- Type
- Channel
-
makeBidiStreamRequest(path, serialize, deserialize [, metadata] [, options])
-
Make a bidirectional stream request with this method on the given channel.
Parameters:
Name Type Argument Description pathstring The path of the method to request
serializegrpc~serialize The serialization function for inputs
deserializegrpc~deserialize The deserialization function for outputs
metadatagrpc.Metadata <optional>
Array of metadata key/value pairs to add to the call
optionsgrpc.Client~CallOptions <optional>
Options map
Returns:
An event emitter for stream related events
-
makeClientStreamRequest(path, serialize, deserialize [, metadata] [, options], callback)
-
Make a client stream request to the given method, using the given serialize and deserialize functions, with the given argument.
Parameters:
Name Type Argument Description pathstring The path of the method to request
serializegrpc~serialize The serialization function for inputs
deserializegrpc~deserialize The deserialization function for outputs
metadatagrpc.Metadata <optional>
Array of metadata key/value pairs to add to the call
optionsgrpc.Client~CallOptions <optional>
Options map
callbackgrpc.Client~requestCallback The callback for when the response is received
Returns:
An event emitter for stream related events
-
makeServerStreamRequest(path, serialize, deserialize, argument [, metadata] [, options])
-
Make a server stream request to the given method, with the given serialize and deserialize function, using the given argument
Parameters:
Name Type Argument Description pathstring The path of the method to request
serializegrpc~serialize The serialization function for inputs
deserializegrpc~deserialize The deserialization function for outputs
argument* The argument to the call. Should be serializable with serialize
metadatagrpc.Metadata <optional>
Array of metadata key/value pairs to add to the call
optionsgrpc.Client~CallOptions <optional>
Options map
Returns:
An event emitter for stream related events
-
makeUnaryRequest(path, serialize, deserialize, argument [, metadata] [, options], callback)
-
Make a unary request to the given method, using the given serialize and deserialize functions, with the given argument.
Parameters:
Name Type Argument Description pathstring The path of the method to request
serializegrpc~serialize The serialization function for inputs
deserializegrpc~deserialize The deserialization function for outputs
argument* The argument to the call. Should be serializable with serialize
metadatagrpc.Metadata <optional>
Metadata to add to the call
optionsgrpc.Client~CallOptions <optional>
Options map
callbackgrpc.Client~requestCallback The callback for when the response is received
Returns:
An event emitter for stream related events
- Type
- grpc~ClientUnaryCall
-
waitForReady(deadline, callback)
-
Wait for the client to be ready. The callback will be called when the client has successfully connected to the server, and it will be called with an error if the attempt to connect to the server has unrecoverablly failed or if the deadline expires. This function will make the channel start connecting if it has not already done so.
Parameters:
Name Type Description deadlinegrpc~Deadline When to stop waiting for a connection.
callbackfunction The callback to call when done attempting to connect.
-
<inner> callInvocationTransformer(callProperties)
-
Call invocation transformer. Has access to the full call properties before a call is processed and can modify most of those properties. Some modifications will have no effect or may cause problems.
Parameters:
Name Type Description callPropertiesgrpc.Client~CallProperties The original call properties
Returns:
The modified call properties.
-
<inner> channelFactory(target, credentials, options)
-
A function that functionally replaces the Channel constructor.
Parameters:
Name Type Description targetstring The address of the server to connect to
credentialsgrpc.ChannelCredentials Channel credentials to use when connecting
optionsgrpc~ChannelOptions A map of channel options that will be passed to the core. The available options are listed in this document.
Returns:
This can either be an actual channel object, or an object with the same API.
- Type
- grpc.Channel
Type Definitions
-
Call
-
Any client call type
Type:
- grpc~ClientUnaryCall | grpc~ClientReadableStream | grpc~ClientWritableStream | grpc~ClientDuplexStream
-
CallOptions
-
Options that can be set on a call.
Type:
- Object
Properties:
Name Type Description deadlinegrpc~Deadline The deadline for the entire call to complete.
hoststring Server hostname to set on the call. Only meaningful if different from the server address used to construct the client.
parentgrpc.Client~Call Parent call. Used in servers when making a call as part of the process of handling a call. Used to propagate some information automatically, as specified by propagate_flags.
propagate_flagsnumber Indicates which properties of a parent call should propagate to this call. Bitwise combination of flags in grpc.propagate.
credentialsgrpc.credentials~CallCredentials The credentials that should be used to make this particular call.
-
CallProperties
-
Properties of a call, for use with a grpc.Client~callInvocationTransformer.
Type:
- Object
Properties:
Name Type Description argument* The call argument. Only preset if the method is unary or server streaming.
metadatagrpc.Metadata The request metadata
callgrpc~Call The call object that will be returned by the client method
channelgrpc.Channel The channel that will be used to make a request
methodDefinitiongrpc~MethodDefinition The MethodDefinition object that describes this method
optionsgrpc.Client~CallOptions The call options passed when making this request
callbackgrpc.Client~requestCallback The callback that will handle the response. Only present if this method is unary or client streaming.
-
requestCallback(error, value)
-
Parameters:
Name Type Argument Description errorgrpc~ServiceError <nullable>
The error, if the call failed
value* The response value, if the call succeeded