@bramanda48/nestjs-service-registry
v0.1.5
Published
Simple Service registry for NestJS
Downloads
3
Maintainers
Readme
Installation & Usage
To see how to use this library, you can refer to the examples folder or follow these instructions.
Install @bramanda48/nestjs-service-registry using npm:
npm install --save @bramanda48/nestjs-service-registry
Install @bramanda48/nestjs-service-registry using yarn:
yarn add @bramanda48/nestjs-service-registry
Server
- Add
ServiceRegistryModule
in your main module
ServiceRegistryModule.forRoot({
mode: 'server'
});
Example :
import { ServiceRegistryModule } from '@bramanda48/nestjs-service-registry';
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
@Module({
imports: [
ServiceRegistryModule.forRoot({
mode: 'server'
})
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
Client
- Add
ServiceRegistryModule
in your main module
ServiceRegistryModule.forRoot({
mode: 'client'
});
- Register your service to registry server
ServiceRegistry.register(app, {
serviceName: 'Service name',
registryServer: 'Registry server url',
host: `Your client host`
});
Example:
import { ServiceRegistry } from '@bramanda48/nestjs-service-registry';
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
await app.listen(1000);
ServiceRegistry.register(app, {
serviceName: 'service-a',
registryServer: 'http://localhost:3000',
host: 'http://127.0.0.1:1000'
});
}
bootstrap();
- To get service data use method
GetSevice
this.serviceRegistry.GetService('Service name');
Example :
this.serviceRegistry.GetService('service-a');
Contributing
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Releasing
- Change package version using
yarn version --new-version <new version>
- Publish to npmjs
yarn publish --access public
License
This project is licensed under the MIT License - see the LICENSE.md file for details.