-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(@artusx/plugin-grpc): remove @GrpcClient(), use @Injectable()
- Loading branch information
Showing
10 changed files
with
87 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
import assert from 'assert'; | ||
import * as grpc from '@grpc/grpc-js'; | ||
import { GrpcClient } from '@artusx/plugin-grpc'; | ||
import { ArtusXGrpcClientClass } from '@artusx/plugin-grpc/types'; | ||
import { ChatClient } from '../proto-codegen/chat'; | ||
import { Inject, ArtusInjectEnum, Injectable, ScopeEnum } from '@artus/core'; | ||
import { ChatClient as Client } from '../proto-codegen/chat'; | ||
|
||
@GrpcClient({ | ||
load: true, | ||
@Injectable({ | ||
scope: ScopeEnum.EXECUTION, | ||
}) | ||
export default class Chat extends ArtusXGrpcClientClass<ChatClient> { | ||
init(addr: string) { | ||
return new ChatClient(addr, grpc.credentials.createInsecure()); | ||
export default class ChatClient extends Client { | ||
constructor(@Inject(ArtusInjectEnum.Config) public config: any) { | ||
const { addr } = config.grpc?.client || {}; | ||
assert(addr, 'addr is required'); | ||
super(addr, grpc.credentials.createInsecure()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,27 @@ | ||
import assert from 'assert'; | ||
import { credentials } from '@artusx/plugin-grpc/types'; | ||
import { Inject } from '@artus/core'; | ||
import { ArtusInjectEnum, Inject, Injectable, ScopeEnum } from '@artus/core'; | ||
import { ArtusXInjectEnum } from '@artusx/utils'; | ||
import { ArtusXGrpcClient, GrpcClient } from '@artusx/plugin-grpc'; | ||
import { ArtusXGrpcClientClass } from '@artusx/plugin-grpc/types'; | ||
import { ChatClient } from '../proto-codegen/chat'; | ||
import { ArtusXGrpcClient } from '@artusx/plugin-grpc'; | ||
|
||
@GrpcClient({ | ||
load: true, | ||
@Injectable({ | ||
scope: ScopeEnum.EXECUTION, | ||
}) | ||
export default class Chat extends ArtusXGrpcClientClass<ChatClient> { | ||
@Inject(ArtusXInjectEnum.GRPC) | ||
grpcClient: ArtusXGrpcClient; | ||
export default class EchoClient { | ||
private echoService: any; | ||
|
||
init(addr: string) { | ||
const EchoService = this.grpcClient.getService('grpc.examples.echo', 'Echo'); | ||
return new EchoService(addr, credentials.createInsecure()); | ||
constructor( | ||
@Inject(ArtusInjectEnum.Config) public config: any, | ||
@Inject(ArtusXInjectEnum.GRPC) public grpcClient: ArtusXGrpcClient | ||
) { | ||
const { addr } = config.grpc?.client || {}; | ||
assert(addr, 'addr is required'); | ||
|
||
const EchoService = grpcClient.getService('grpc.examples.echo', 'Echo'); | ||
this.echoService = new EchoService(addr, credentials.createInsecure()); | ||
} | ||
|
||
UnaryEcho(call: any, callback: any) { | ||
this.echoService.UnaryEcho(call, callback); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.