mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-29 01:00:05 +00:00
maestro connection with microservices - clients and modules
This commit is contained in:
@@ -1,17 +1,22 @@
|
||||
// import { join } from 'path';
|
||||
// import { ClientOptions, Transport } from '@nestjs/microservices';
|
||||
import { OutputProtofile } from '@victorradael/protospack';
|
||||
import { ClientOptions, Transport } from '@nestjs/microservices';
|
||||
import { credentials } from '@grpc/grpc-js';
|
||||
|
||||
// export const OutputsClientConfiguration: ClientOptions = {
|
||||
// transport: Transport.GRPC,
|
||||
// options: {
|
||||
// //url: `${process.env.USERS_SVC_URL}:${process.env.USERS_SVC_PORT}`,
|
||||
// url: `127.0.0.1:50053`,
|
||||
// package: 'output',
|
||||
// protoPath: join(__dirname, '..', 'proto', 'output.proto'),
|
||||
// loader: {
|
||||
// enums: String,
|
||||
// objects: true,
|
||||
// arrays: true,
|
||||
// },
|
||||
// },
|
||||
// };
|
||||
export class OutputsClientConfiguration {
|
||||
config(): ClientOptions {
|
||||
return {
|
||||
transport: Transport.GRPC,
|
||||
options: {
|
||||
url: process.env.OUTFACTORY_URL,
|
||||
package: 'output',
|
||||
// credentials: credentials.createSsl(),
|
||||
protoPath: OutputProtofile,
|
||||
loader: {
|
||||
enums: String,
|
||||
objects: true,
|
||||
arrays: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,57 +1,165 @@
|
||||
// import {
|
||||
// Controller,
|
||||
// Delete,
|
||||
// Get,
|
||||
// OnModuleInit,
|
||||
// Param,
|
||||
// Post,
|
||||
// Put,
|
||||
// } from '@nestjs/common';
|
||||
// import {
|
||||
// Client,
|
||||
// ClientGrpc,
|
||||
// MessagePattern,
|
||||
// Payload,
|
||||
// } from '@nestjs/microservices';
|
||||
// import { OutputsService } from './outputs.service';
|
||||
// import { CreateOutputDto } from './dto/create-output.dto';
|
||||
// import { UpdateOutputDto } from './dto/update-output.dto';
|
||||
// import { ApiTags } from '@nestjs/swagger';
|
||||
// import { GrpcClientConfiguration } from './client.config';
|
||||
import {
|
||||
Controller,
|
||||
Delete,
|
||||
Get,
|
||||
Inject,
|
||||
OnModuleInit,
|
||||
Param,
|
||||
Post,
|
||||
Put,
|
||||
} from '@nestjs/common';
|
||||
import {
|
||||
ClientGrpc,
|
||||
Payload,
|
||||
} from '@nestjs/microservices';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
import { OutputsServiceInterface } from '@victorradael/protospack';
|
||||
import { objectCamelToSnake } from 'src/utils/CaseConverter';
|
||||
import { ICreateOutputRequest, IIdRequest, IOutputUpdateRequest } from './interfaces';
|
||||
|
||||
// @Controller('output')
|
||||
// export class OutputsClientService implements OnModuleInit {
|
||||
// @Client(GrpcClientConfiguration)
|
||||
// private outputServiceClient: ClientGrpc;
|
||||
@Controller('output')
|
||||
export class OutputsClientService implements OnModuleInit {
|
||||
private outputService: OutputsServiceInterface;
|
||||
constructor(
|
||||
@Inject('OUTPUTS_PACKAGE')private readonly grpcClient: ClientGrpc,
|
||||
){}
|
||||
|
||||
// private outputService: OutputsService;
|
||||
onModuleInit() {
|
||||
this.outputService =
|
||||
this.grpcClient.getService<OutputsServiceInterface>('OutputService');
|
||||
}
|
||||
|
||||
// onModuleInit() {
|
||||
// this.outputService =
|
||||
// this.outputServiceClient.getService<OutputsService>('OutputService');
|
||||
// }
|
||||
// @Post()
|
||||
// create(@Payload() createOutputDto: CreateOutputDto) {
|
||||
// return this.outputService.create(createOutputDto);
|
||||
// }
|
||||
async create(@Payload() createOutputDto:ICreateOutputRequest ) {
|
||||
console.log('OutputClientService', 'Create');
|
||||
|
||||
// @Get()
|
||||
// list() {
|
||||
// return this.outputService.list();
|
||||
// }
|
||||
const createOutputResponse = await new Promise((resolve, reject) => {
|
||||
this.outputService.create(createOutputDto).subscribe({
|
||||
next(x) {
|
||||
resolve(x);
|
||||
},
|
||||
error(err) {
|
||||
console.log('Observable Error');
|
||||
reject(err);
|
||||
},
|
||||
complete() {
|
||||
console.log('done');
|
||||
},
|
||||
});
|
||||
})
|
||||
.then((res) => res)
|
||||
.catch((err) => {
|
||||
throw new Error(err);
|
||||
});
|
||||
|
||||
const convertedItem = objectCamelToSnake(createOutputResponse["item"])
|
||||
createOutputResponse["item"] = convertedItem
|
||||
|
||||
// @Get(':id')
|
||||
// show(@Param() id: string) {
|
||||
// return this.outputService.show(id);
|
||||
// }
|
||||
return createOutputResponse;
|
||||
}
|
||||
|
||||
// @Put(':id')
|
||||
// update(@Param() id: string, @Payload() updateOutputDto: UpdateOutputDto) {
|
||||
// return this.outputService.update(id, updateOutputDto);
|
||||
// }
|
||||
async findAll() {
|
||||
console.log('OutputClientService', 'FindAll');
|
||||
|
||||
// @Delete(':id')
|
||||
// remove(@Param() id: string) {
|
||||
// return this.outputService.remove(id);
|
||||
// }
|
||||
// }
|
||||
const findAllOutputResponse = await new Promise((resolve, reject) => {
|
||||
this.outputService.findAll({}).subscribe({
|
||||
next(x) {
|
||||
resolve(x);
|
||||
},
|
||||
error(err) {
|
||||
console.log('Observable Error');
|
||||
reject(err);
|
||||
},
|
||||
complete() {
|
||||
console.log('done');
|
||||
},
|
||||
});
|
||||
})
|
||||
.then((res) => res)
|
||||
.catch((err) => {
|
||||
throw new Error(err);
|
||||
});
|
||||
|
||||
const convertedOutputs = findAllOutputResponse['outputs'].map((ot)=>{
|
||||
return objectCamelToSnake(ot)
|
||||
})
|
||||
|
||||
return {outputs:convertedOutputs};
|
||||
}
|
||||
|
||||
async findOne({id}: IIdRequest) {
|
||||
console.log('OutputClientService', 'FindOne');
|
||||
|
||||
const findOneOutputResponse = await new Promise((resolve, reject) => {
|
||||
this.outputService.findOne({id}).subscribe({
|
||||
next(x) {
|
||||
resolve(x);
|
||||
},
|
||||
error(err) {
|
||||
console.log('Observable Error');
|
||||
reject(err);
|
||||
},
|
||||
complete() {
|
||||
console.log('done');
|
||||
},
|
||||
});
|
||||
})
|
||||
.then((res) => res)
|
||||
.catch((err) => {
|
||||
throw new Error(err);
|
||||
});
|
||||
|
||||
|
||||
return objectCamelToSnake(findOneOutputResponse);
|
||||
}
|
||||
|
||||
|
||||
async update(updateOutPutDTO: IOutputUpdateRequest) {
|
||||
console.log('OutputClientService', 'Update');
|
||||
|
||||
const updateOutputResponse = await new Promise((resolve, reject) => {
|
||||
this.outputService.update(updateOutPutDTO).subscribe({
|
||||
next(x) {
|
||||
resolve(x);
|
||||
},
|
||||
error(err) {
|
||||
console.log('Observable Error');
|
||||
reject(err);
|
||||
},
|
||||
complete() {
|
||||
console.log('done');
|
||||
},
|
||||
});
|
||||
})
|
||||
.then((res) => res)
|
||||
.catch((err) => {
|
||||
throw new Error(err);
|
||||
});
|
||||
|
||||
return objectCamelToSnake(updateOutputResponse);
|
||||
}
|
||||
|
||||
async remove({id}:IIdRequest) {
|
||||
console.log('OutputClientService', 'Remove');
|
||||
|
||||
const removeOutputResponse = await new Promise((resolve, reject) => {
|
||||
this.outputService.remove({id}).subscribe({
|
||||
next(x) {
|
||||
resolve(x);
|
||||
},
|
||||
error(err) {
|
||||
console.log('Observable Error');
|
||||
reject(err);
|
||||
},
|
||||
complete() {
|
||||
console.log('done');
|
||||
},
|
||||
});
|
||||
})
|
||||
.then((res) => res)
|
||||
.catch((err) => {
|
||||
throw new Error(err);
|
||||
});
|
||||
|
||||
return removeOutputResponse;
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+22
@@ -0,0 +1,22 @@
|
||||
export interface ICreateOutputRequest {
|
||||
operation: string;
|
||||
name: string;
|
||||
plugin: string;
|
||||
values: Values;
|
||||
}
|
||||
|
||||
export interface Values {
|
||||
prefix: string;
|
||||
}
|
||||
|
||||
export interface IIdRequest{
|
||||
id:string;
|
||||
}
|
||||
|
||||
export interface IOutputUpdateRequest {
|
||||
id: string;
|
||||
operation: string;
|
||||
values: Values;
|
||||
plugin: string;
|
||||
name: string;
|
||||
}
|
||||
Reference in New Issue
Block a user