mirror of
https://github.com/dadosfera/maestro.git
synced 2026-09-16 15:04:48 +00:00
Client Refactor
This commit is contained in:
@@ -1,32 +1,38 @@
|
||||
import { credentials } from '@grpc/grpc-js';
|
||||
import { ClientOptions, Transport } from '@nestjs/microservices';
|
||||
import {
|
||||
ClientsProviderAsyncOptions,
|
||||
GrpcOptions,
|
||||
Transport,
|
||||
} from '@nestjs/microservices';
|
||||
import { ConnectionManager } from '@dadosfera/protospack-v2';
|
||||
|
||||
export class ConnectionClientConfiguration {
|
||||
config(): ClientOptions {
|
||||
return {
|
||||
transport: Transport.GRPC,
|
||||
options: {
|
||||
url: process.env.INFACTORY_URL,
|
||||
package: [
|
||||
ConnectionManager.ProtoPackages.WritePackage,
|
||||
ConnectionManager.ProtoPackages.ReadPackage,
|
||||
],
|
||||
// credentials: undefined,
|
||||
credentials: process.env.LOCAL_ENV
|
||||
? undefined
|
||||
: credentials.createSsl(),
|
||||
protoPath: [
|
||||
ConnectionManager.ProtoPaths.WriteFilePath,
|
||||
ConnectionManager.ProtoPaths.ReadFilePath,
|
||||
],
|
||||
loader: {
|
||||
keepCase: true,
|
||||
enums: String,
|
||||
objects: true,
|
||||
arrays: true,
|
||||
},
|
||||
public name = 'ConnectionClientConfiguration';
|
||||
private config: GrpcOptions = {
|
||||
transport: Transport.GRPC,
|
||||
options: {
|
||||
url: process.env.INFACTORY_URL,
|
||||
package: [
|
||||
ConnectionManager.ProtoPackages.WritePackage,
|
||||
ConnectionManager.ProtoPackages.ReadPackage,
|
||||
],
|
||||
// credentials: undefined,
|
||||
credentials: process.env.LOCAL_ENV ? undefined : credentials.createSsl(),
|
||||
protoPath: [
|
||||
ConnectionManager.ProtoPaths.WriteFilePath,
|
||||
ConnectionManager.ProtoPaths.ReadFilePath,
|
||||
],
|
||||
loader: {
|
||||
keepCase: true,
|
||||
enums: String,
|
||||
objects: true,
|
||||
arrays: true,
|
||||
},
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
providerOptions: ClientsProviderAsyncOptions = {
|
||||
name: this.name,
|
||||
...this.config,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -9,12 +9,14 @@ import { ClientGrpc } from '@nestjs/microservices';
|
||||
import { ConnectionManager } from '@dadosfera/protospack-v2';
|
||||
import { lastValueFrom } from 'rxjs';
|
||||
import { GetConnectionsRes } from './dtos/connection';
|
||||
import { ConnectionClientConfiguration } from './client.config';
|
||||
|
||||
export class ConnectionClientService implements OnModuleInit {
|
||||
private connectionServiceRead: ConnectionManager.ReadService.ConnectionManagerReadServices;
|
||||
private connectionServiceWrite: ConnectionManager.WriteService.ConnectionManagerWriteServices;
|
||||
constructor(
|
||||
@Inject('CONNECTION_PACKAGE') private readonly grpcClient: ClientGrpc,
|
||||
@Inject(ConnectionClientConfiguration.name)
|
||||
private readonly grpcClient: ClientGrpc,
|
||||
) {}
|
||||
|
||||
onModuleInit() {
|
||||
|
||||
@@ -10,14 +10,7 @@ const client = new ConnectionClientConfiguration();
|
||||
@Module({
|
||||
controllers: [ConnectionController],
|
||||
providers: [ConnectionClientService, DadosferaLogger],
|
||||
imports: [
|
||||
ClientsModule.register([
|
||||
{
|
||||
name: 'CONNECTION_PACKAGE',
|
||||
...client.config(),
|
||||
},
|
||||
]),
|
||||
],
|
||||
imports: [ClientsModule.register([client.providerOptions])],
|
||||
exports: [ConnectionClientService],
|
||||
})
|
||||
export class ConnectionModule {}
|
||||
|
||||
@@ -1,31 +1,36 @@
|
||||
import { credentials } from '@grpc/grpc-js';
|
||||
import { ClientOptions, Transport } from '@nestjs/microservices';
|
||||
import {
|
||||
ClientsProviderAsyncOptions,
|
||||
GrpcOptions,
|
||||
Transport,
|
||||
} from '@nestjs/microservices';
|
||||
import { ConnectorManager } from '@dadosfera/protospack-v2';
|
||||
|
||||
export class ConnectorClientConfiguration {
|
||||
config(): ClientOptions {
|
||||
return {
|
||||
transport: Transport.GRPC,
|
||||
options: {
|
||||
url: process.env.INFACTORY_URL,
|
||||
package: [
|
||||
ConnectorManager.ProtoPackages.WritePackage,
|
||||
ConnectorManager.ProtoPackages.ReadPackage,
|
||||
],
|
||||
credentials: process.env.LOCAL_ENV
|
||||
? undefined
|
||||
: credentials.createSsl(),
|
||||
protoPath: [
|
||||
ConnectorManager.ProtoPaths.WriteFilePath,
|
||||
ConnectorManager.ProtoPaths.ReadFilePath,
|
||||
],
|
||||
loader: {
|
||||
keepCase: true,
|
||||
enums: String,
|
||||
objects: true,
|
||||
arrays: true,
|
||||
},
|
||||
public name = 'ConnectorClientConfiguration';
|
||||
private config: GrpcOptions = {
|
||||
transport: Transport.GRPC,
|
||||
options: {
|
||||
url: process.env.INFACTORY_URL,
|
||||
package: [
|
||||
ConnectorManager.ProtoPackages.WritePackage,
|
||||
ConnectorManager.ProtoPackages.ReadPackage,
|
||||
],
|
||||
credentials: process.env.LOCAL_ENV ? undefined : credentials.createSsl(),
|
||||
protoPath: [
|
||||
ConnectorManager.ProtoPaths.WriteFilePath,
|
||||
ConnectorManager.ProtoPaths.ReadFilePath,
|
||||
],
|
||||
loader: {
|
||||
keepCase: true,
|
||||
enums: String,
|
||||
objects: true,
|
||||
arrays: true,
|
||||
},
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
providerOptions: ClientsProviderAsyncOptions = {
|
||||
name: this.name,
|
||||
...this.config,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -8,12 +8,14 @@ import {
|
||||
import { ClientGrpc } from '@nestjs/microservices';
|
||||
import { ConnectorManager } from '@dadosfera/protospack-v2';
|
||||
import { lastValueFrom } from 'rxjs';
|
||||
import { ConnectorClientConfiguration } from './client.config';
|
||||
|
||||
export class ConnectorClientService implements OnModuleInit {
|
||||
private connectorServiceRead: ConnectorManager.ReadService.ConnectorManagerReadServices;
|
||||
private connectorServiceWrite: ConnectorManager.WriteService.ConnectorManagerWriteServices;
|
||||
constructor(
|
||||
@Inject('CONNECTOR_PACKAGE') private readonly grpcClient: ClientGrpc,
|
||||
@Inject(ConnectorClientConfiguration.name)
|
||||
private readonly grpcClient: ClientGrpc,
|
||||
) {}
|
||||
|
||||
onModuleInit() {
|
||||
|
||||
@@ -5,18 +5,11 @@ import { ConnectorClientConfiguration } from './client.config';
|
||||
import { ConnectorController } from './connector.controller';
|
||||
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
||||
|
||||
const connectorClient = new ConnectorClientConfiguration();
|
||||
const client = new ConnectorClientConfiguration();
|
||||
|
||||
@Module({
|
||||
controllers: [ConnectorController],
|
||||
providers: [ConnectorClientService, DadosferaLogger],
|
||||
imports: [
|
||||
ClientsModule.register([
|
||||
{
|
||||
name: 'CONNECTOR_PACKAGE',
|
||||
...connectorClient.config(),
|
||||
},
|
||||
]),
|
||||
],
|
||||
imports: [ClientsModule.register([client.providerOptions])],
|
||||
})
|
||||
export class ConnectorModule {}
|
||||
|
||||
@@ -7,6 +7,8 @@ import {
|
||||
import { NetworkConfig } from '@dadosfera/protospack-v2';
|
||||
|
||||
export class NetworkConfigGrpcClient {
|
||||
public name = 'NetworkConfigGrpcClient';
|
||||
|
||||
private config: GrpcOptions = {
|
||||
transport: Transport.GRPC,
|
||||
options: {
|
||||
@@ -30,7 +32,7 @@ export class NetworkConfigGrpcClient {
|
||||
},
|
||||
};
|
||||
providerOptions: ClientProviderOptions = {
|
||||
name: 'NetworkConfigGrpcClient',
|
||||
name: this.name,
|
||||
...this.config,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -13,13 +13,15 @@ import {
|
||||
UpdateNetworkConfigReq,
|
||||
UpdateNetworkConfigRes,
|
||||
} from './dto/network-config';
|
||||
import { NetworkConfigGrpcClient } from './network-config-client.config';
|
||||
|
||||
@Injectable()
|
||||
export class NetworkConfigService {
|
||||
private networkConfigReadClient: NetworkConfig.ReadService.NetworkConfigReadService;
|
||||
private networkConfigWriteClient: NetworkConfig.WriteService.NetworkConfigWriteService;
|
||||
constructor(
|
||||
@Inject('NetworkConfigGrpcClient') private readonly grpcClient: ClientGrpc,
|
||||
@Inject(NetworkConfigGrpcClient.name)
|
||||
private readonly grpcClient: ClientGrpc,
|
||||
) {
|
||||
this.networkConfigReadClient =
|
||||
grpcClient.getService<NetworkConfig.ReadService.NetworkConfigReadService>(
|
||||
|
||||
Reference in New Issue
Block a user