feat: implement bullmq for print queue and bull-board integration
This commit is contained in:
parent
6e45369855
commit
895311ae56
167
README.md
167
README.md
|
|
@ -1,98 +1,113 @@
|
|||
<p align="center">
|
||||
<a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="120" alt="Nest Logo" /></a>
|
||||
</p>
|
||||
# Especificação Técnica: Microserviço de Impressão
|
||||
|
||||
[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456
|
||||
[circleci-url]: https://circleci.com/gh/nestjs/nest
|
||||
Este documento descreve as especificações técnicas, endpoints e padrões de arquitetura do Microserviço de Impressão. O sistema é projetado para o processamento assíncrono de documentos e integração com hardware de impressão local.
|
||||
|
||||
<p align="center">A progressive <a href="http://nodejs.org" target="_blank">Node.js</a> framework for building efficient and scalable server-side applications.</p>
|
||||
<p align="center">
|
||||
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a>
|
||||
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a>
|
||||
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/dm/@nestjs/common.svg" alt="NPM Downloads" /></a>
|
||||
<a href="https://circleci.com/gh/nestjs/nest" target="_blank"><img src="https://img.shields.io/circleci/build/github/nestjs/nest/master" alt="CircleCI" /></a>
|
||||
<a href="https://discord.gg/G7Qnnhy" target="_blank"><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a>
|
||||
<a href="https://opencollective.com/nest#backer" target="_blank"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
|
||||
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a>
|
||||
<a href="https://paypal.me/kamilmysliwiec" target="_blank"><img src="https://img.shields.io/badge/Donate-PayPal-ff3f59.svg" alt="Donate us"/></a>
|
||||
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://img.shields.io/badge/Support%20us-Open%20Collective-41B883.svg" alt="Support us"></a>
|
||||
<a href="https://twitter.com/nestframework" target="_blank"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow" alt="Follow us on Twitter"></a>
|
||||
</p>
|
||||
<!--[](https://opencollective.com/nest#backer)
|
||||
[](https://opencollective.com/nest#sponsor)-->
|
||||
## Arquitetura e Fluxo de Dados
|
||||
|
||||
## Description
|
||||
A solução utiliza uma arquitetura baseada em filas para assegurar a resiliência e a escalabilidade do processamento de impressão.
|
||||
|
||||
[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository.
|
||||
### Componentes Principais
|
||||
|
||||
## Project setup
|
||||
1. **API REST**: Interface para recepção de requisições de impressão.
|
||||
2. **BullMQ (Redis)**: Engine de mensageria para gestão de filas e persistência temporária de tarefas (jobs).
|
||||
3. **Queue Worker (PrinterProcessor)**: Componente responsável por consumir a fila, realizar a renderização de documentos via Puppeteer e comunicar-se com os drivers do sistema operacional.
|
||||
4. **Persistência (Oracle)**: Integração via TypeORM para registro de dados operacionais em base de dados corporativa.
|
||||
|
||||
```bash
|
||||
$ npm install
|
||||
### Fluxo de Operação
|
||||
|
||||
1. A API recebe uma solicitação de impressão via HTTP.
|
||||
2. A tarefa é registrada na fila `printer` gerenciada pelo BullMQ.
|
||||
3. O `PrinterProcessor` (WorkerHost) processa a tarefa, converte o conteúdo HTML em PDF e envia para o spooler de impressão.
|
||||
|
||||
---
|
||||
|
||||
## Configurações do Sistema
|
||||
|
||||
### Variáveis de Ambiente
|
||||
|
||||
O serviço utiliza as seguintes definições no arquivo `.env`:
|
||||
|
||||
| Variável | Descrição | Exemplo |
|
||||
| :------------------- | :------------------------------- | :------------------------ |
|
||||
| `REDIS_HOST` | Endereço do servidor Redis | `localhost` |
|
||||
| `REDIS_PORT` | Porta do servidor Redis | `6379` |
|
||||
| `DB_USERNAME` | Usuário do Banco de Dados Oracle | `admin` |
|
||||
| `DB_PASSWORD` | Senha do Banco de Dados Oracle | `1234` |
|
||||
| `DB_CONNECT_STRING` | String de conexão Oracle | `(DESCRIPTION=...)` |
|
||||
| `ORACLE_CLIENT_PATH` | Caminho do Oracle Instant Client | `C:\oracle\instantclient` |
|
||||
|
||||
### Pré-requisitos
|
||||
|
||||
- Node.js >= 20.0.0
|
||||
- Redis Server
|
||||
- Oracle Instant Client (Thick Mode habilitado)
|
||||
|
||||
---
|
||||
|
||||
## Endpoints da API
|
||||
|
||||
### 1. Sistema e Inventário
|
||||
|
||||
#### Listar Impressoras Disponíveis
|
||||
|
||||
Retorna a lista de periféricos de impressão configurados no host.
|
||||
|
||||
- **Método:** `GET`
|
||||
- **Endpoint:** `/printer/list`
|
||||
- **Resposta:** `PrinterDto[]`
|
||||
|
||||
### 2. Operações de Impressão
|
||||
|
||||
#### Impressão de Conteúdo HTML
|
||||
|
||||
Enfileira a conversão de HTML para PDF seguido da impressão física.
|
||||
|
||||
- **Método:** `POST`
|
||||
- **Endpoint:** `/printer/:printerName/print-html`
|
||||
- **Payload:**
|
||||
|
||||
```json
|
||||
{
|
||||
"html": "string",
|
||||
"width": "string (ex: 80mm)",
|
||||
"height": "string (ex: 40mm)",
|
||||
"jobId": "string (opcional)"
|
||||
}
|
||||
```
|
||||
|
||||
## Compile and run the project
|
||||
#### Impressão Direta (ESC/POS)
|
||||
|
||||
```bash
|
||||
# development
|
||||
$ npm run start
|
||||
Envio de comandos diretamente para impressoras térmicas.
|
||||
|
||||
# watch mode
|
||||
$ npm run start:dev
|
||||
- **Método:** `POST`
|
||||
- **Endpoint:** `/printer/:printerName/print`
|
||||
- **Payload:**
|
||||
|
||||
# production mode
|
||||
$ npm run start:prod
|
||||
```json
|
||||
{
|
||||
"lines": ["string"],
|
||||
"alignment": "left | center | right",
|
||||
"upsideDown": "boolean"
|
||||
}
|
||||
```
|
||||
|
||||
## Run tests
|
||||
---
|
||||
|
||||
```bash
|
||||
# unit tests
|
||||
$ npm run test
|
||||
## Observabilidade e Gestão
|
||||
|
||||
# e2e tests
|
||||
$ npm run test:e2e
|
||||
### Bull Board
|
||||
|
||||
# test coverage
|
||||
$ npm run test:cov
|
||||
```
|
||||
A interface de monitoramento em tempo real das filas está disponível no endpoint:
|
||||
`http://localhost:3000/queues`
|
||||
|
||||
## Deployment
|
||||
Permite a visualização de tarefas ativas, concluídas e falhas, além da reinjeção manual de jobs.
|
||||
|
||||
When you're ready to deploy your NestJS application to production, there are some key steps you can take to ensure it runs as efficiently as possible. Check out the [deployment documentation](https://docs.nestjs.com/deployment) for more information.
|
||||
### Telemetria
|
||||
|
||||
If you are looking for a cloud-based platform to deploy your NestJS application, check out [Mau](https://mau.nestjs.com), our official platform for deploying NestJS applications on AWS. Mau makes deployment straightforward and fast, requiring just a few simple steps:
|
||||
O serviço está instrumentado com **OpenTelemetry**, exportando traces via protocolo OTLP para análise de performance e rastreabilidade distribuída.
|
||||
|
||||
```bash
|
||||
$ npm install -g @nestjs/mau
|
||||
$ mau deploy
|
||||
```
|
||||
---
|
||||
|
||||
With Mau, you can deploy your application in just a few clicks, allowing you to focus on building features rather than managing infrastructure.
|
||||
## Estrutura Técnica
|
||||
|
||||
## Resources
|
||||
|
||||
Check out a few resources that may come in handy when working with NestJS:
|
||||
|
||||
- Visit the [NestJS Documentation](https://docs.nestjs.com) to learn more about the framework.
|
||||
- For questions and support, please visit our [Discord channel](https://discord.gg/G7Qnnhy).
|
||||
- To dive deeper and get more hands-on experience, check out our official video [courses](https://courses.nestjs.com/).
|
||||
- Deploy your application to AWS with the help of [NestJS Mau](https://mau.nestjs.com) in just a few clicks.
|
||||
- Visualize your application graph and interact with the NestJS application in real-time using [NestJS Devtools](https://devtools.nestjs.com).
|
||||
- Need help with your project (part-time to full-time)? Check out our official [enterprise support](https://enterprise.nestjs.com).
|
||||
- To stay in the loop and get updates, follow us on [X](https://x.com/nestframework) and [LinkedIn](https://linkedin.com/company/nestjs).
|
||||
- Looking for a job, or have a job to offer? Check out our official [Jobs board](https://jobs.nestjs.com).
|
||||
|
||||
## Support
|
||||
|
||||
Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support).
|
||||
|
||||
## Stay in touch
|
||||
|
||||
- Author - [Kamil Myśliwiec](https://twitter.com/kammysliwiec)
|
||||
- Website - [https://nestjs.com](https://nestjs.com/)
|
||||
- Twitter - [@nestframework](https://twitter.com/nestframework)
|
||||
|
||||
## License
|
||||
|
||||
Nest is [MIT licensed](https://github.com/nestjs/nest/blob/master/LICENSE).
|
||||
O projeto é construído sobre o framework NestJS, utilizando `@nestjs/bullmq` para a gestão de filas. O processador de impressão é injetado como um provider global no `AppModule` para garantir a execução contínua do worker dentro do contexto da aplicação.
|
||||
|
|
|
|||
Loading…
Reference in New Issue