Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
d6010dd
refactor(RabbitMQ): add refactoring to improve the internal workings …
lucassm02 Apr 25, 2025
875df51
feat: add functionality to extract RabbitMQ options from the RABBIT_O…
lucassm02 Apr 25, 2025
62dc511
chore(RabbitMQ): add protocol adaptation to new implementations
lucassm02 Apr 30, 2025
08e4ad7
chore(Flow): add an improvement to the processing of handlers
lucassm02 Apr 30, 2025
3447689
chore: add optimization to APM decorators
lucassm02 Apr 30, 2025
9151e59
fix(searchLabels): add optimization to prevent the maximum call stack…
lucassm02 Apr 30, 2025
0313559
chore: change when elastic is started
lucassm02 Apr 30, 2025
df92bde
feat(apm): add APM decorators to handlers so they can be instrumented
lucassm02 Apr 30, 2025
a3b2d4e
feat(reprocessing)!: add normalize and normalizeOptions utility
lucassm02 May 2, 2025
87fb4fb
chore!: renames non-standard folder, β€˜utils’ became 'util'
lucassm02 May 2, 2025
6197499
fix(reprocessing): add normalization before message validation
lucassm02 May 2, 2025
7855a18
chore: add improvements to the application startup and shutdown process
lucassm02 May 6, 2025
111b47f
chore: add improvements to MemCached's connection process and connect…
lucassm02 May 6, 2025
b957482
chore: update .env.example
lucassm02 May 6, 2025
7431a38
docs: update changelog
lucassm02 May 6, 2025
46fb6aa
docs: update project version
lucassm02 May 6, 2025
89155f3
chore: remove unused file
lucassm02 May 6, 2025
9b649d2
test: add automated test correction
lucassm02 May 6, 2025
cd26a60
chore: update .env.example
lucassm02 May 6, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ DB_PASSWORD=
DB_PORT=

# MONGO
MONGO_ENABLED=true
MONGO_USER=
MONGO_PASSWORD=
MONGO_HOST=
Expand All @@ -41,6 +42,8 @@ MONGO_NAME=
MONGO_AUTH_SOURCE=

# RABBIT
RABBIT_ENABLED=
RABBIT_OPTIONS=
RABBIT_USER=
RABBIT_PASSWORD=
RABBIT_HOST=
Expand Down
123 changes: 0 additions & 123 deletions .gitlab-ci.yml

This file was deleted.

36 changes: 36 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,42 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.3.0] - 2025-05-06

### Added

- New `normalize` and `normalizeOptions` utilities for payload normalization in the reprocessing module.
- APM decorators for handlers, enabling instrumentation.
- Functionality to extract RabbitMQ options from the `RABBIT_OPTIONS` environment variable.

### Changed

- Renamed non-standard folder from `utils` to `util`.
- Improved application startup and shutdown process.
- Enhanced MemCached connection process and added connection timeout.
- Updated the `.env.example` file.
- Adjusted when Elastic is started.
- Added protocol adaptation for new RabbitMQ implementations.
- Improved handler processing logic to prevent subsequent handlers from executing prematurely.
- Optimized APM decorators.

### Fixed

- Added normalization before message validation in the reprocessing module.
- Optimized `searchLabels` to prevent maximum call stack overflow.

### Deprecated

- _No deprecations._

### Removed

- _No removals._

### Security

- _No security fixes.

## [2.2.0] - 2025-03-19

### Added
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "template-microservice",
"version": "1.0.0",
"version": "2.3.0",
"scripts": {
"helm:gen": "NODE_NO_WARNINGS=1 node script/helm/index.mjs",
"helm:gen:production": "NODE_NO_WARNINGS=1 node script/helm/index.mjs -e production --scan-routes",
Expand Down
2 changes: 1 addition & 1 deletion src/data/protocols/mq/publish-in-exchange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ export interface PublishInExchangeService {
message: object,
routingKey: string,
headers?: object
): Promise<void>;
): Promise<boolean>;
}
6 changes: 5 additions & 1 deletion src/data/protocols/mq/publish-in-queue.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
export interface PublishInQueueService {
publishInQueue(queue: string, message: object, headers?: object): void;
publishInQueue(
queue: string,
message: object,
headers?: object
): Promise<boolean>;
}
File renamed without changes.
2 changes: 1 addition & 1 deletion src/data/usecases/elasticsearch/es-create-event.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { GetAPMTransactionIds } from '@/data/protocols/apm';
import { CreateDocumentService } from '@/data/protocols/elasticsearch';
import { FormatDate } from '@/data/protocols/utils';
import { FormatDate } from '@/data/protocols/util';
import { CreateEvent } from '@/domain/usecases/event';

export class EsCreateEvent implements CreateEvent {
Expand Down
2 changes: 1 addition & 1 deletion src/data/usecases/elasticsearch/es-update-event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
GetDocumentByIdService,
UpdateDocumentService
} from '@/data/protocols/elasticsearch';
import { FormatDate, Merge } from '@/data/protocols/utils';
import { FormatDate, Merge } from '@/data/protocols/util';
import { UpdateEvent } from '@/domain/usecases/event';

export class EsUpdateEvent implements UpdateEvent {
Expand Down
11 changes: 9 additions & 2 deletions src/infra/cache/cache-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ export class CacheServer {
private connectionString!: string;
private connected: boolean = false;

private CONNECTION_TIMEOUT = 10000;
private CONNECTION_RETIES = 5;
private RETIES_TIMEOUT = 2;

public Error = {
CONNECTION_ERROR: 'Server not connected!',
CREDENTIALS_NOT_DEFINED: 'Server credentials not defined!',
Expand Down Expand Up @@ -77,12 +81,15 @@ export class CacheServer {
if (!this.connectionString)
throw new Error(this.Error.CREDENTIALS_NOT_DEFINED);
if (this.connected) return;
this.server = memjs.Client.create(this.connectionString);
this.server = memjs.Client.create(this.connectionString, {
timeout: this.CONNECTION_TIMEOUT,
retries: this.CONNECTION_RETIES,
retry_delay: this.RETIES_TIMEOUT
});
this.connected = true;
}

public disconnect() {
if (!this.connected) return;
this.server.close();
this.connected = false;
}
Expand Down
62 changes: 48 additions & 14 deletions src/infra/http/util/web-server/web-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { SharedState } from '@/presentation/protocols/shared-state';
import { internalImplementationError, serverError } from '@/presentation/utils';
import {
DICTIONARY,
apmSpan,
convertCamelCaseKeysToSnakeCase,
convertSnakeCaseKeysToCamelCase,
logger
Expand Down Expand Up @@ -245,17 +246,8 @@ export class WebServer {
}
}

return new Promise((resolve, reject) => {
this.fastify.server.close((error) => {
if (error) {
reject(error);
return;
}

logger.log({ level: 'info', message: 'Shutting down server' });
resolve(null);
});
});
await this.fastify.close();
logger.log({ level: 'info', message: 'Shutting down server' });
}

public setBaseUrl(url: string) {
Expand Down Expand Up @@ -395,9 +387,51 @@ export class WebServer {
this.makeSetStateInRequest(state)
];

const response = await (typeof middleware !== 'function'
? middleware.handle(request, stateHook, next)
: middleware(request, reply, next, stateHook));
function handler() {
const decoratorOptions = {
options: {
name: '',
subType: 'handler'
},
params: {}
};

if (typeof middleware === 'function') {
decoratorOptions.options.name = middleware.name;
decoratorOptions.params = { stateHook: 3 };
const decorator = apmSpan(decoratorOptions);
const proto = {};

const methodName = middleware.name;

const desc: PropertyDescriptor = {
value: middleware.bind(null),
writable: true,
configurable: true,
enumerable: false
};

const newDesc = decorator(proto, methodName, desc);

return newDesc.value(request, reply, next, stateHook);
}

decoratorOptions.options.name = middleware.constructor.name;
decoratorOptions.params = { stateHook: 1 };
const decorator = apmSpan(decoratorOptions);

const proto = middleware.constructor.prototype;
const methodName = 'handle';
const desc = Object.getOwnPropertyDescriptor(proto, methodName)!;

const newDesc = decorator(proto, methodName, desc);

Object.defineProperty(proto, methodName, newDesc);

return middleware.handle(request, stateHook, next);
}

const response = await handler();

if (!response) return;

Expand Down
Loading
Loading