@mohib22kool/balance-service-lib
v0.1.2
Published
A NestJS library providing balance queue and Redis update service
Maintainers
Readme
Balance Service Library
A lightweight NestJS library that pushes balance update messages into a RabbitMQ queue named BALANCE and consumes them to update Redis keys in the form userId:balance:{INR:10,USD:20}.
Features
- Class-based
BalanceServicewith small, focused methods - Uses
amqplibfor RabbitMQ andioredisfor Redis - Easy to import as a linked package (
npm linkor local path)
Getting Started
Install dependencies:
npm installBuild the library:
npm run buildIn your NestJS application, add the library as a dependency. If you're developing locally, you can use
npm linkor a relative path inpackage.json:"dependencies": { "balance-service-lib": "file:../az-omi-balance" }Import the module and inject the service:
import { Module } from '@nestjs/common'; import { BalanceModule, BalanceService } from 'balance-service-lib'; @Module({ imports: [BalanceModule], providers: [], }) export class AppModule { constructor(private readonly balance: BalanceService) { // ensure service is initialized by Nest } }Use the service to push messages:
this.balance.pushToQueue('1234', 'INR', -10);
The consumer automatically starts on module initialization and persists balance data to Redis.
Configuration
RABBIT_URL– URL to RabbitMQ server (default:amqp://localhost)REDIS_URL– URL to Redis server (default:redis://localhost:6379/0)
