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