Skip to content

Commit

Permalink
test(grpc): fix
Browse files Browse the repository at this point in the history
  • Loading branch information
waitingsong committed Nov 13, 2024
1 parent da0032d commit b35590d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
9 changes: 5 additions & 4 deletions packages/grpc/src/comsumer/clients.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,10 @@ export class GRPCClients extends Map {
}

let genericFunctionName;
const rpcMethod = options.metadata.get('rpc.method.type')?.[0];
switch (genericFunctionSelector) {
case 0:
if (! options.metadata.get('rpc.method.type')) {
if (!rpcMethod) {
options.metadata.set('rpc.method.type', 'unary');
}
genericFunctionName = new ClientUnaryRequest(
Expand All @@ -125,7 +126,7 @@ export class GRPCClients extends Map {
);
break;
case 1:
if (! options.metadata.get('rpc.method.type')) {
if (!rpcMethod) {
options.metadata.set('rpc.method.type', 'server'); // server streaming
}
genericFunctionName = new ClientReadableRequest(
Expand All @@ -135,7 +136,7 @@ export class GRPCClients extends Map {
);
break;
case 2:
if (! options.metadata.get('rpc.method.type')) {
if (!rpcMethod) {
options.metadata.set('rpc.method.type', 'client'); // client streaming
}
genericFunctionName = new ClientWritableRequest(
Expand All @@ -145,7 +146,7 @@ export class GRPCClients extends Map {
);
break;
case 3:
if (! options.metadata.get('rpc.method.type')) {
if (!rpcMethod) {
options.metadata.set('rpc.method.type', 'bidi'); // bidirectional streaming
}
genericFunctionName = new ClientDuplexStreamRequest(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { GrpcMethod, GrpcStreamTypeEnum, MSProviderType, Provide, Provider } from '@midwayjs/core';
import { GrpcMethod, GrpcStreamTypeEnum, Inject, MSProviderType, Provide, Provider } from '@midwayjs/core';
import { Context } from '../../../../../src';
import { math } from '../interface';
import { Metadata } from '@grpc/grpc-js';

Expand All @@ -8,6 +9,9 @@ import { Metadata } from '@grpc/grpc-js';
@Provider(MSProviderType.GRPC, { package: 'math' })
export class Math implements math.Math {

@Inject()
ctx: Context;

sumDataList = [];

@GrpcMethod()
Expand Down

0 comments on commit b35590d

Please sign in to comment.