├── .gitignore ├── README.md ├── microservice-client ├── README.md ├── dist │ ├── app.controller.d.ts │ ├── app.controller.js │ ├── app.controller.js.map │ ├── app.module.d.ts │ ├── app.module.js │ ├── app.module.js.map │ ├── app.service.d.ts │ ├── app.service.js │ ├── app.service.js.map │ ├── main.d.ts │ ├── main.js │ ├── main.js.map │ ├── message.event.d.ts │ ├── message.event.js │ ├── message.event.js.map │ ├── tsconfig.build.tsbuildinfo │ ├── user-created.event.d.ts │ ├── user-created.event.js │ └── user-created.event.js.map ├── nest-cli.json ├── package-lock.json ├── package.json ├── src │ ├── app.controller.spec.ts │ ├── app.controller.ts │ ├── app.module.ts │ ├── app.service.ts │ ├── main.ts │ └── message.event.ts ├── test │ ├── app.e2e-spec.ts │ └── jest-e2e.json ├── tsconfig.build.json ├── tsconfig.json └── tslint.json ├── microservices-app ├── README.md ├── dist │ ├── app.controller.d.ts │ ├── app.controller.js │ ├── app.controller.js.map │ ├── app.module.d.ts │ ├── app.module.js │ ├── app.module.js.map │ ├── app.service.d.ts │ ├── app.service.js │ ├── app.service.js.map │ ├── main.d.ts │ ├── main.js │ ├── main.js.map │ └── tsconfig.build.tsbuildinfo ├── nest-cli.json ├── package-lock.json ├── package.json ├── src │ ├── app.controller.spec.ts │ ├── app.controller.ts │ ├── app.module.ts │ ├── app.service.ts │ └── main.ts ├── test │ ├── app.e2e-spec.ts │ └── jest-e2e.json ├── tsconfig.build.json ├── tsconfig.json └── tslint.json └── package-lock.json /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # nestjs-rabbitmq-microservice 2 | A simple microservice implementation using Nest JS and RabbitMQ with client and server by buzz-lightyear 3 | -------------------------------------------------------------------------------- /microservice-client/README.md: -------------------------------------------------------------------------------- 1 |

2 | Nest Logo 3 |

4 | 5 | [travis-image]: https://api.travis-ci.org/nestjs/nest.svg?branch=master 6 | [travis-url]: https://travis-ci.org/nestjs/nest 7 | [linux-image]: https://img.shields.io/travis/nestjs/nest/master.svg?label=linux 8 | [linux-url]: https://travis-ci.org/nestjs/nest 9 | 10 |

A progressive Node.js framework for building efficient and scalable server-side applications, heavily inspired by Angular.

11 |

12 | NPM Version 13 | Package License 14 | NPM Downloads 15 | Travis 16 | Linux 17 | Coverage 18 | Gitter 19 | Backers on Open Collective 20 | Sponsors on Open Collective 21 | 22 | 23 |

24 | 26 | 27 | ## Description 28 | 29 | [Nest](https://github.com/nestjs/nest) framework TypeScript starter repository. 30 | 31 | ## Installation 32 | 33 | ```bash 34 | $ npm install 35 | ``` 36 | 37 | ## Running the app 38 | 39 | ```bash 40 | # development 41 | $ npm run start 42 | 43 | # watch mode 44 | $ npm run start:dev 45 | 46 | # production mode 47 | $ npm run start:prod 48 | ``` 49 | 50 | ## Test 51 | 52 | ```bash 53 | # unit tests 54 | $ npm run test 55 | 56 | # e2e tests 57 | $ npm run test:e2e 58 | 59 | # test coverage 60 | $ npm run test:cov 61 | ``` 62 | 63 | ## Support 64 | 65 | 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). 66 | 67 | ## Stay in touch 68 | 69 | - Author - [Kamil Myśliwiec](https://kamilmysliwiec.com) 70 | - Website - [https://nestjs.com](https://nestjs.com/) 71 | - Twitter - [@nestframework](https://twitter.com/nestframework) 72 | 73 | ## License 74 | 75 | Nest is [MIT licensed](LICENSE). 76 | -------------------------------------------------------------------------------- /microservice-client/dist/app.controller.d.ts: -------------------------------------------------------------------------------- 1 | import { ClientProxy } from '@nestjs/microservices'; 2 | export declare class AppController { 3 | private readonly client; 4 | constructor(client: ClientProxy); 5 | onApplicationBootstrap(): Promise; 6 | getHello(): string; 7 | } 8 | -------------------------------------------------------------------------------- /microservice-client/dist/app.controller.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { 3 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; 4 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 5 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; 6 | return c > 3 && r && Object.defineProperty(target, key, r), r; 7 | }; 8 | var __metadata = (this && this.__metadata) || function (k, v) { 9 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); 10 | }; 11 | var __param = (this && this.__param) || function (paramIndex, decorator) { 12 | return function (target, key) { decorator(target, key, paramIndex); } 13 | }; 14 | Object.defineProperty(exports, "__esModule", { value: true }); 15 | const common_1 = require("@nestjs/common"); 16 | const microservices_1 = require("@nestjs/microservices"); 17 | const message_event_1 = require("./message.event"); 18 | let AppController = class AppController { 19 | constructor(client) { 20 | this.client = client; 21 | } 22 | async onApplicationBootstrap() { 23 | } 24 | getHello() { 25 | this.client.emit('message_printed', new message_event_1.Message('Hello World')); 26 | return 'Hello World printed'; 27 | } 28 | }; 29 | __decorate([ 30 | common_1.Get(), 31 | __metadata("design:type", Function), 32 | __metadata("design:paramtypes", []), 33 | __metadata("design:returntype", void 0) 34 | ], AppController.prototype, "getHello", null); 35 | AppController = __decorate([ 36 | common_1.Controller(), 37 | __param(0, common_1.Inject('HELLO_SERVICE')), 38 | __metadata("design:paramtypes", [microservices_1.ClientProxy]) 39 | ], AppController); 40 | exports.AppController = AppController; 41 | //# sourceMappingURL=app.controller.js.map -------------------------------------------------------------------------------- /microservice-client/dist/app.controller.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"app.controller.js","sourceRoot":"","sources":["../src/app.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,2CAAyD;AAEzD,yDAAoD;AACpD,mDAA0C;AAG1C,IAAa,aAAa,GAA1B,MAAa,aAAa;IACxB,YAAsD,MAAmB;QAAnB,WAAM,GAAN,MAAM,CAAa;IAAI,CAAC;IAE9E,KAAK,CAAC,sBAAsB;IAE5B,CAAC;IAGD,QAAQ;QACN,IAAI,CAAC,MAAM,CAAC,IAAI,CAAM,iBAAiB,EAAE,IAAI,uBAAO,CAAC,aAAa,CAAC,CAAC,CAAC;QACrE,OAAO,qBAAqB,CAAC;IAC/B,CAAC;CACF,CAAA;AAJC;IADC,YAAG,EAAE;;;;6CAIL;AAXU,aAAa;IADzB,mBAAU,EAAE;IAEE,WAAA,eAAM,CAAC,eAAe,CAAC,CAAA;qCAA0B,2BAAW;GAD9D,aAAa,CAYzB;AAZY,sCAAa"} -------------------------------------------------------------------------------- /microservice-client/dist/app.module.d.ts: -------------------------------------------------------------------------------- 1 | export declare class AppModule { 2 | } 3 | -------------------------------------------------------------------------------- /microservice-client/dist/app.module.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { 3 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; 4 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 5 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; 6 | return c > 3 && r && Object.defineProperty(target, key, r), r; 7 | }; 8 | Object.defineProperty(exports, "__esModule", { value: true }); 9 | const common_1 = require("@nestjs/common"); 10 | const app_controller_1 = require("./app.controller"); 11 | const app_service_1 = require("./app.service"); 12 | const microservices_1 = require("@nestjs/microservices"); 13 | let AppModule = class AppModule { 14 | }; 15 | AppModule = __decorate([ 16 | common_1.Module({ 17 | imports: [ 18 | microservices_1.ClientsModule.register([ 19 | { 20 | name: 'HELLO_SERVICE', transport: microservices_1.Transport.RMQ, 21 | options: { 22 | urls: ['amqp://guest:guest@localhost:5672/hello'], 23 | queue: 'user-messages', 24 | queueOptions: { 25 | durable: false 26 | }, 27 | }, 28 | }, 29 | ]), 30 | ], 31 | controllers: [app_controller_1.AppController], 32 | providers: [app_service_1.AppService], 33 | }) 34 | ], AppModule); 35 | exports.AppModule = AppModule; 36 | //# sourceMappingURL=app.module.js.map -------------------------------------------------------------------------------- /microservice-client/dist/app.module.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"app.module.js","sourceRoot":"","sources":["../src/app.module.ts"],"names":[],"mappings":";;;;;;;;AAAA,2CAAwC;AACxC,qDAAiD;AACjD,+CAA2C;AAC3C,yDAAiE;AAoBjE,IAAa,SAAS,GAAtB,MAAa,SAAS;CAErB,CAAA;AAFY,SAAS;IAlBrB,eAAM,CAAC;QACN,OAAO,EAAE;YACP,6BAAa,CAAC,QAAQ,CAAC;gBACrB;oBACE,IAAI,EAAE,eAAe,EAAE,SAAS,EAAE,yBAAS,CAAC,GAAG;oBAC/C,OAAO,EAAE;wBACP,IAAI,EAAE,CAAC,yCAAyC,CAAC;wBACjD,KAAK,EAAE,eAAe;wBACtB,YAAY,EAAE;4BACZ,OAAO,EAAE,KAAK;yBACf;qBACF;iBACF;aACF,CAAC;SACH;QACD,WAAW,EAAE,CAAC,8BAAa,CAAC;QAC5B,SAAS,EAAE,CAAC,wBAAU,CAAC;KACxB,CAAC;GACW,SAAS,CAErB;AAFY,8BAAS"} -------------------------------------------------------------------------------- /microservice-client/dist/app.service.d.ts: -------------------------------------------------------------------------------- 1 | export declare class AppService { 2 | getHello(): string; 3 | } 4 | -------------------------------------------------------------------------------- /microservice-client/dist/app.service.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { 3 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; 4 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 5 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; 6 | return c > 3 && r && Object.defineProperty(target, key, r), r; 7 | }; 8 | Object.defineProperty(exports, "__esModule", { value: true }); 9 | const common_1 = require("@nestjs/common"); 10 | let AppService = class AppService { 11 | getHello() { 12 | return 'Hello World!'; 13 | } 14 | }; 15 | AppService = __decorate([ 16 | common_1.Injectable() 17 | ], AppService); 18 | exports.AppService = AppService; 19 | //# sourceMappingURL=app.service.js.map -------------------------------------------------------------------------------- /microservice-client/dist/app.service.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"app.service.js","sourceRoot":"","sources":["../src/app.service.ts"],"names":[],"mappings":";;;;;;;;AAAA,2CAA4C;AAG5C,IAAa,UAAU,GAAvB,MAAa,UAAU;IACrB,QAAQ;QACN,OAAO,cAAc,CAAC;IACxB,CAAC;CACF,CAAA;AAJY,UAAU;IADtB,mBAAU,EAAE;GACA,UAAU,CAItB;AAJY,gCAAU"} -------------------------------------------------------------------------------- /microservice-client/dist/main.d.ts: -------------------------------------------------------------------------------- 1 | export {}; 2 | -------------------------------------------------------------------------------- /microservice-client/dist/main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | const core_1 = require("@nestjs/core"); 4 | const app_module_1 = require("./app.module"); 5 | async function bootstrap() { 6 | const app = await core_1.NestFactory.create(app_module_1.AppModule); 7 | await app.listen(3000); 8 | } 9 | bootstrap(); 10 | //# sourceMappingURL=main.js.map -------------------------------------------------------------------------------- /microservice-client/dist/main.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";;AAAA,uCAA2C;AAC3C,6CAAyC;AAEzC,KAAK,UAAU,SAAS;IACtB,MAAM,GAAG,GAAG,MAAM,kBAAW,CAAC,MAAM,CAAC,sBAAS,CAAC,CAAC;IAChD,MAAM,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AACzB,CAAC;AACD,SAAS,EAAE,CAAC"} -------------------------------------------------------------------------------- /microservice-client/dist/message.event.d.ts: -------------------------------------------------------------------------------- 1 | export declare class Message { 2 | text: string; 3 | constructor(text: any); 4 | } 5 | -------------------------------------------------------------------------------- /microservice-client/dist/message.event.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | class Message { 4 | constructor(text) { 5 | this.text = text; 6 | } 7 | } 8 | exports.Message = Message; 9 | //# sourceMappingURL=message.event.js.map -------------------------------------------------------------------------------- /microservice-client/dist/message.event.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"message.event.js","sourceRoot":"","sources":["../src/message.event.ts"],"names":[],"mappings":";;AAAA,MAAa,OAAO;IAGhB,YAAY,IAAI;QACZ,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACrB,CAAC;CACJ;AAND,0BAMC"} -------------------------------------------------------------------------------- /microservice-client/dist/user-created.event.d.ts: -------------------------------------------------------------------------------- 1 | export declare class UserCreated { 2 | id: number; 3 | name: string; 4 | constructor(id: any, name: any); 5 | } 6 | -------------------------------------------------------------------------------- /microservice-client/dist/user-created.event.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | class UserCreated { 4 | constructor(id, name) { 5 | this.id = id; 6 | this.name = name; 7 | } 8 | } 9 | exports.UserCreated = UserCreated; 10 | //# sourceMappingURL=user-created.event.js.map -------------------------------------------------------------------------------- /microservice-client/dist/user-created.event.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"user-created.event.js","sourceRoot":"","sources":["../src/user-created.event.ts"],"names":[],"mappings":";;AAAA,MAAa,WAAW;IAIpB,YAAY,EAAE,EAAE,IAAI;QAChB,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACrB,CAAC;CACJ;AARD,kCAQC"} -------------------------------------------------------------------------------- /microservice-client/nest-cli.json: -------------------------------------------------------------------------------- 1 | { 2 | "collection": "@nestjs/schematics", 3 | "sourceRoot": "src" 4 | } 5 | -------------------------------------------------------------------------------- /microservice-client/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "microservice-client", 3 | "version": "0.0.1", 4 | "description": "", 5 | "author": "", 6 | "license": "MIT", 7 | "scripts": { 8 | "prebuild": "rimraf dist", 9 | "build": "nest build", 10 | "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", 11 | "start": "nest start", 12 | "start:dev": "nest start --watch", 13 | "start:debug": "nest start --debug --watch", 14 | "start:prod": "node dist/main", 15 | "lint": "tslint -p tsconfig.json -c tslint.json", 16 | "test": "jest", 17 | "test:watch": "jest --watch", 18 | "test:cov": "jest --coverage", 19 | "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand", 20 | "test:e2e": "jest --config ./test/jest-e2e.json" 21 | }, 22 | "dependencies": { 23 | "@nestjs/common": "^6.7.2", 24 | "@nestjs/core": "^6.7.2", 25 | "@nestjs/microservices": "^6.10.14", 26 | "@nestjs/platform-express": "^6.7.2", 27 | "amqp-connection-manager": "^3.2.0", 28 | "amqplib": "^0.5.5", 29 | "reflect-metadata": "^0.1.13", 30 | "rimraf": "^3.0.0", 31 | "rxjs": "^6.5.3" 32 | }, 33 | "devDependencies": { 34 | "@nestjs/cli": "^6.9.0", 35 | "@nestjs/schematics": "^6.7.0", 36 | "@nestjs/testing": "^6.7.1", 37 | "@types/express": "^4.17.1", 38 | "@types/jest": "^24.0.18", 39 | "@types/node": "^12.7.5", 40 | "@types/supertest": "^2.0.8", 41 | "jest": "^24.9.0", 42 | "prettier": "^1.18.2", 43 | "supertest": "^4.0.2", 44 | "ts-jest": "^24.1.0", 45 | "ts-loader": "^6.1.1", 46 | "ts-node": "^8.4.1", 47 | "tsconfig-paths": "^3.9.0", 48 | "tslint": "^5.20.0", 49 | "typescript": "^3.6.3" 50 | }, 51 | "jest": { 52 | "moduleFileExtensions": [ 53 | "js", 54 | "json", 55 | "ts" 56 | ], 57 | "rootDir": "src", 58 | "testRegex": ".spec.ts$", 59 | "transform": { 60 | "^.+\\.(t|j)s$": "ts-jest" 61 | }, 62 | "coverageDirectory": "../coverage", 63 | "testEnvironment": "node" 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /microservice-client/src/app.controller.spec.ts: -------------------------------------------------------------------------------- 1 | import { Test, TestingModule } from '@nestjs/testing'; 2 | import { AppController } from './app.controller'; 3 | import { AppService } from './app.service'; 4 | 5 | describe('AppController', () => { 6 | let appController: AppController; 7 | 8 | beforeEach(async () => { 9 | const app: TestingModule = await Test.createTestingModule({ 10 | controllers: [AppController], 11 | providers: [AppService], 12 | }).compile(); 13 | 14 | appController = app.get(AppController); 15 | }); 16 | 17 | describe('root', () => { 18 | it('should return "Hello World!"', () => { 19 | expect(appController.getHello()).toBe('Hello World!'); 20 | }); 21 | }); 22 | }); 23 | -------------------------------------------------------------------------------- /microservice-client/src/app.controller.ts: -------------------------------------------------------------------------------- 1 | import { Controller, Get, Inject } from '@nestjs/common'; 2 | import { AppService } from './app.service'; 3 | import { ClientProxy } from '@nestjs/microservices'; 4 | import { Message } from './message.event'; 5 | 6 | @Controller() 7 | export class AppController { 8 | constructor(@Inject('HELLO_SERVICE') private readonly client: ClientProxy) { } 9 | 10 | async onApplicationBootstrap() { 11 | //await this.client.connect(); 12 | } 13 | 14 | @Get() 15 | getHello() { 16 | this.client.emit('message_printed', new Message('Hello World')); 17 | return 'Hello World printed'; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /microservice-client/src/app.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { AppController } from './app.controller'; 3 | import { AppService } from './app.service'; 4 | import { Transport, ClientsModule } from '@nestjs/microservices'; 5 | 6 | @Module({ 7 | imports: [ 8 | ClientsModule.register([ 9 | { 10 | name: 'HELLO_SERVICE', transport: Transport.RMQ, 11 | options: { 12 | urls: ['amqp://guest:guest@localhost:5672/hello'], 13 | queue: 'user-messages', 14 | queueOptions: { 15 | durable: false 16 | }, 17 | }, 18 | }, 19 | ]), 20 | ], 21 | controllers: [AppController], 22 | providers: [AppService], 23 | }) 24 | export class AppModule { 25 | 26 | } 27 | -------------------------------------------------------------------------------- /microservice-client/src/app.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@nestjs/common'; 2 | 3 | @Injectable() 4 | export class AppService { 5 | getHello(): string { 6 | return 'Hello World!'; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /microservice-client/src/main.ts: -------------------------------------------------------------------------------- 1 | import { NestFactory } from '@nestjs/core'; 2 | import { AppModule } from './app.module'; 3 | 4 | async function bootstrap() { 5 | const app = await NestFactory.create(AppModule); 6 | await app.listen(3000); 7 | } 8 | bootstrap(); 9 | -------------------------------------------------------------------------------- /microservice-client/src/message.event.ts: -------------------------------------------------------------------------------- 1 | export class Message { 2 | text: string; 3 | 4 | constructor(text) { 5 | this.text = text; 6 | } 7 | } -------------------------------------------------------------------------------- /microservice-client/test/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { Test, TestingModule } from '@nestjs/testing'; 2 | import { INestApplication } from '@nestjs/common'; 3 | import * as request from 'supertest'; 4 | import { AppModule } from './../src/app.module'; 5 | 6 | describe('AppController (e2e)', () => { 7 | let app: INestApplication; 8 | 9 | beforeEach(async () => { 10 | const moduleFixture: TestingModule = await Test.createTestingModule({ 11 | imports: [AppModule], 12 | }).compile(); 13 | 14 | app = moduleFixture.createNestApplication(); 15 | await app.init(); 16 | }); 17 | 18 | it('/ (GET)', () => { 19 | return request(app.getHttpServer()) 20 | .get('/') 21 | .expect(200) 22 | .expect('Hello World!'); 23 | }); 24 | }); 25 | -------------------------------------------------------------------------------- /microservice-client/test/jest-e2e.json: -------------------------------------------------------------------------------- 1 | { 2 | "moduleFileExtensions": ["js", "json", "ts"], 3 | "rootDir": ".", 4 | "testEnvironment": "node", 5 | "testRegex": ".e2e-spec.ts$", 6 | "transform": { 7 | "^.+\\.(t|j)s$": "ts-jest" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /microservice-client/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "exclude": ["node_modules", "test", "dist", "**/*spec.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /microservice-client/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "declaration": true, 5 | "removeComments": true, 6 | "emitDecoratorMetadata": true, 7 | "experimentalDecorators": true, 8 | "target": "es2017", 9 | "sourceMap": true, 10 | "outDir": "./dist", 11 | "baseUrl": "./", 12 | "incremental": true 13 | }, 14 | "exclude": ["node_modules", "dist"] 15 | } 16 | -------------------------------------------------------------------------------- /microservice-client/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "defaultSeverity": "error", 3 | "extends": ["tslint:recommended"], 4 | "jsRules": { 5 | "no-unused-expression": true 6 | }, 7 | "rules": { 8 | "quotemark": [true, "single"], 9 | "member-access": [false], 10 | "ordered-imports": [false], 11 | "max-line-length": [true, 150], 12 | "member-ordering": [false], 13 | "interface-name": [false], 14 | "arrow-parens": false, 15 | "object-literal-sort-keys": false 16 | }, 17 | "rulesDirectory": [] 18 | } 19 | -------------------------------------------------------------------------------- /microservices-app/README.md: -------------------------------------------------------------------------------- 1 |

2 | Nest Logo 3 |

4 | 5 | [travis-image]: https://api.travis-ci.org/nestjs/nest.svg?branch=master 6 | [travis-url]: https://travis-ci.org/nestjs/nest 7 | [linux-image]: https://img.shields.io/travis/nestjs/nest/master.svg?label=linux 8 | [linux-url]: https://travis-ci.org/nestjs/nest 9 | 10 |

A progressive Node.js framework for building efficient and scalable server-side applications, heavily inspired by Angular.

11 |

12 | NPM Version 13 | Package License 14 | NPM Downloads 15 | Travis 16 | Linux 17 | Coverage 18 | Gitter 19 | Backers on Open Collective 20 | Sponsors on Open Collective 21 | 22 | 23 |

24 | 26 | 27 | ## Description 28 | 29 | [Nest](https://github.com/nestjs/nest) framework TypeScript starter repository. 30 | 31 | ## Installation 32 | 33 | ```bash 34 | $ npm install 35 | ``` 36 | 37 | ## Running the app 38 | 39 | ```bash 40 | # development 41 | $ npm run start 42 | 43 | # watch mode 44 | $ npm run start:dev 45 | 46 | # production mode 47 | $ npm run start:prod 48 | ``` 49 | 50 | ## Test 51 | 52 | ```bash 53 | # unit tests 54 | $ npm run test 55 | 56 | # e2e tests 57 | $ npm run test:e2e 58 | 59 | # test coverage 60 | $ npm run test:cov 61 | ``` 62 | 63 | ## Support 64 | 65 | 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). 66 | 67 | ## Stay in touch 68 | 69 | - Author - [Kamil Myśliwiec](https://kamilmysliwiec.com) 70 | - Website - [https://nestjs.com](https://nestjs.com/) 71 | - Twitter - [@nestframework](https://twitter.com/nestframework) 72 | 73 | ## License 74 | 75 | Nest is [MIT licensed](LICENSE). 76 | -------------------------------------------------------------------------------- /microservices-app/dist/app.controller.d.ts: -------------------------------------------------------------------------------- 1 | export declare class AppController { 2 | constructor(); 3 | handleMessagePrinted(data: Record): Promise; 4 | } 5 | -------------------------------------------------------------------------------- /microservices-app/dist/app.controller.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { 3 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; 4 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 5 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; 6 | return c > 3 && r && Object.defineProperty(target, key, r), r; 7 | }; 8 | var __metadata = (this && this.__metadata) || function (k, v) { 9 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); 10 | }; 11 | Object.defineProperty(exports, "__esModule", { value: true }); 12 | const common_1 = require("@nestjs/common"); 13 | const microservices_1 = require("@nestjs/microservices"); 14 | let AppController = class AppController { 15 | constructor() { } 16 | async handleMessagePrinted(data) { 17 | console.log(data.text); 18 | } 19 | }; 20 | __decorate([ 21 | microservices_1.EventPattern('message_printed'), 22 | __metadata("design:type", Function), 23 | __metadata("design:paramtypes", [Object]), 24 | __metadata("design:returntype", Promise) 25 | ], AppController.prototype, "handleMessagePrinted", null); 26 | AppController = __decorate([ 27 | common_1.Controller(), 28 | __metadata("design:paramtypes", []) 29 | ], AppController); 30 | exports.AppController = AppController; 31 | //# sourceMappingURL=app.controller.js.map -------------------------------------------------------------------------------- /microservices-app/dist/app.controller.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"app.controller.js","sourceRoot":"","sources":["../src/app.controller.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,2CAAiD;AACjD,yDAAqD;AAGrD,IAAa,aAAa,GAA1B,MAAa,aAAa;IACxB,gBAAgB,CAAC;IAIjB,KAAK,CAAC,oBAAoB,CAAC,IAA6B;QACtD,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACzB,CAAC;CACF,CAAA;AAHC;IADC,4BAAY,CAAC,iBAAiB,CAAC;;;;yDAG/B;AAPU,aAAa;IADzB,mBAAU,EAAE;;GACA,aAAa,CAQzB;AARY,sCAAa"} -------------------------------------------------------------------------------- /microservices-app/dist/app.module.d.ts: -------------------------------------------------------------------------------- 1 | export declare class AppModule { 2 | } 3 | -------------------------------------------------------------------------------- /microservices-app/dist/app.module.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { 3 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; 4 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 5 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; 6 | return c > 3 && r && Object.defineProperty(target, key, r), r; 7 | }; 8 | Object.defineProperty(exports, "__esModule", { value: true }); 9 | const common_1 = require("@nestjs/common"); 10 | const app_controller_1 = require("./app.controller"); 11 | const app_service_1 = require("./app.service"); 12 | let AppModule = class AppModule { 13 | }; 14 | AppModule = __decorate([ 15 | common_1.Module({ 16 | imports: [], 17 | controllers: [app_controller_1.AppController], 18 | providers: [app_service_1.AppService], 19 | }) 20 | ], AppModule); 21 | exports.AppModule = AppModule; 22 | //# sourceMappingURL=app.module.js.map -------------------------------------------------------------------------------- /microservices-app/dist/app.module.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"app.module.js","sourceRoot":"","sources":["../src/app.module.ts"],"names":[],"mappings":";;;;;;;;AAAA,2CAAwC;AACxC,qDAAiD;AACjD,+CAA2C;AAO3C,IAAa,SAAS,GAAtB,MAAa,SAAS;CAAG,CAAA;AAAZ,SAAS;IALrB,eAAM,CAAC;QACN,OAAO,EAAE,EAAE;QACX,WAAW,EAAE,CAAC,8BAAa,CAAC;QAC5B,SAAS,EAAE,CAAC,wBAAU,CAAC;KACxB,CAAC;GACW,SAAS,CAAG;AAAZ,8BAAS"} -------------------------------------------------------------------------------- /microservices-app/dist/app.service.d.ts: -------------------------------------------------------------------------------- 1 | export declare class AppService { 2 | getHello(): string; 3 | } 4 | -------------------------------------------------------------------------------- /microservices-app/dist/app.service.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { 3 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; 4 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 5 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; 6 | return c > 3 && r && Object.defineProperty(target, key, r), r; 7 | }; 8 | Object.defineProperty(exports, "__esModule", { value: true }); 9 | const common_1 = require("@nestjs/common"); 10 | let AppService = class AppService { 11 | getHello() { 12 | return 'Hello World!'; 13 | } 14 | }; 15 | AppService = __decorate([ 16 | common_1.Injectable() 17 | ], AppService); 18 | exports.AppService = AppService; 19 | //# sourceMappingURL=app.service.js.map -------------------------------------------------------------------------------- /microservices-app/dist/app.service.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"app.service.js","sourceRoot":"","sources":["../src/app.service.ts"],"names":[],"mappings":";;;;;;;;AAAA,2CAA4C;AAG5C,IAAa,UAAU,GAAvB,MAAa,UAAU;IACrB,QAAQ;QACN,OAAO,cAAc,CAAC;IACxB,CAAC;CACF,CAAA;AAJY,UAAU;IADtB,mBAAU,EAAE;GACA,UAAU,CAItB;AAJY,gCAAU"} -------------------------------------------------------------------------------- /microservices-app/dist/main.d.ts: -------------------------------------------------------------------------------- 1 | export {}; 2 | -------------------------------------------------------------------------------- /microservices-app/dist/main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | const core_1 = require("@nestjs/core"); 4 | const app_module_1 = require("./app.module"); 5 | const microservices_1 = require("@nestjs/microservices"); 6 | async function bootstrap() { 7 | const app = await core_1.NestFactory.createMicroservice(app_module_1.AppModule, { 8 | transport: microservices_1.Transport.RMQ, 9 | options: { 10 | urls: ['amqp://guest:guest@localhost:5672/hello'], 11 | queue: 'user-messages', 12 | queueOptions: { 13 | durable: false 14 | }, 15 | }, 16 | }); 17 | await app.listen(() => console.log('Microservice is listening')); 18 | } 19 | bootstrap(); 20 | //# sourceMappingURL=main.js.map -------------------------------------------------------------------------------- /microservices-app/dist/main.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";;AAAA,uCAA2C;AAC3C,6CAAyC;AACzC,yDAAkD;AAElD,KAAK,UAAU,SAAS;IACtB,MAAM,GAAG,GAAG,MAAM,kBAAW,CAAC,kBAAkB,CAAC,sBAAS,EAAE;QAC1D,SAAS,EAAE,yBAAS,CAAC,GAAG;QACxB,OAAO,EAAE;YACP,IAAI,EAAE,CAAC,yCAAyC,CAAC;YACjD,KAAK,EAAE,eAAe;YACtB,YAAY,EAAE;gBACZ,OAAO,EAAE,KAAK;aACf;SACF;KACF,CAAC,CAAC;IACH,MAAM,GAAG,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAC,CAAC;AACnE,CAAC;AACD,SAAS,EAAE,CAAC"} -------------------------------------------------------------------------------- /microservices-app/nest-cli.json: -------------------------------------------------------------------------------- 1 | { 2 | "collection": "@nestjs/schematics", 3 | "sourceRoot": "src" 4 | } 5 | -------------------------------------------------------------------------------- /microservices-app/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "microservices-app", 3 | "version": "0.0.1", 4 | "description": "", 5 | "author": "", 6 | "license": "MIT", 7 | "scripts": { 8 | "prebuild": "rimraf dist", 9 | "build": "nest build", 10 | "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", 11 | "start": "nest start", 12 | "start:dev": "nest start --watch", 13 | "start:debug": "nest start --debug --watch", 14 | "start:prod": "node dist/main", 15 | "lint": "tslint -p tsconfig.json -c tslint.json", 16 | "test": "jest", 17 | "test:watch": "jest --watch", 18 | "test:cov": "jest --coverage", 19 | "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand", 20 | "test:e2e": "jest --config ./test/jest-e2e.json" 21 | }, 22 | "dependencies": { 23 | "@nestjs/common": "^6.7.2", 24 | "@nestjs/core": "^6.7.2", 25 | "@nestjs/microservices": "^6.10.14", 26 | "@nestjs/platform-express": "^6.7.2", 27 | "amqp-connection-manager": "^3.2.0", 28 | "amqplib": "^0.5.5", 29 | "reflect-metadata": "^0.1.13", 30 | "rimraf": "^3.0.0", 31 | "rxjs": "^6.5.3" 32 | }, 33 | "devDependencies": { 34 | "@nestjs/cli": "^6.9.0", 35 | "@nestjs/schematics": "^6.7.0", 36 | "@nestjs/testing": "^6.7.1", 37 | "@types/express": "^4.17.1", 38 | "@types/jest": "^24.0.18", 39 | "@types/node": "^12.7.5", 40 | "@types/supertest": "^2.0.8", 41 | "jest": "^24.9.0", 42 | "prettier": "^1.18.2", 43 | "supertest": "^4.0.2", 44 | "ts-jest": "^24.1.0", 45 | "ts-loader": "^6.1.1", 46 | "ts-node": "^8.4.1", 47 | "tsconfig-paths": "^3.9.0", 48 | "tslint": "^5.20.0", 49 | "typescript": "^3.6.3" 50 | }, 51 | "jest": { 52 | "moduleFileExtensions": [ 53 | "js", 54 | "json", 55 | "ts" 56 | ], 57 | "rootDir": "src", 58 | "testRegex": ".spec.ts$", 59 | "transform": { 60 | "^.+\\.(t|j)s$": "ts-jest" 61 | }, 62 | "coverageDirectory": "../coverage", 63 | "testEnvironment": "node" 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /microservices-app/src/app.controller.spec.ts: -------------------------------------------------------------------------------- 1 | import { Test, TestingModule } from '@nestjs/testing'; 2 | import { AppController } from './app.controller'; 3 | import { AppService } from './app.service'; 4 | 5 | describe('AppController', () => { 6 | let appController: AppController; 7 | 8 | beforeEach(async () => { 9 | const app: TestingModule = await Test.createTestingModule({ 10 | controllers: [AppController], 11 | providers: [AppService], 12 | }).compile(); 13 | 14 | appController = app.get(AppController); 15 | }); 16 | 17 | describe('root', () => { 18 | it('should return "Hello World!"', () => { 19 | expect(appController.getHello()).toBe('Hello World!'); 20 | }); 21 | }); 22 | }); 23 | -------------------------------------------------------------------------------- /microservices-app/src/app.controller.ts: -------------------------------------------------------------------------------- 1 | import { Controller, Get } from '@nestjs/common'; 2 | import { EventPattern } from '@nestjs/microservices'; 3 | 4 | @Controller() 5 | export class AppController { 6 | constructor() { } 7 | 8 | 9 | @EventPattern('message_printed') 10 | async handleMessagePrinted(data: Record) { 11 | console.log(data.text); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /microservices-app/src/app.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { AppController } from './app.controller'; 3 | import { AppService } from './app.service'; 4 | 5 | @Module({ 6 | imports: [], 7 | controllers: [AppController], 8 | providers: [AppService], 9 | }) 10 | export class AppModule {} 11 | -------------------------------------------------------------------------------- /microservices-app/src/app.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@nestjs/common'; 2 | 3 | @Injectable() 4 | export class AppService { 5 | getHello(): string { 6 | return 'Hello World!'; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /microservices-app/src/main.ts: -------------------------------------------------------------------------------- 1 | import { NestFactory } from '@nestjs/core'; 2 | import { AppModule } from './app.module'; 3 | import { Transport } from '@nestjs/microservices'; 4 | 5 | async function bootstrap() { 6 | const app = await NestFactory.createMicroservice(AppModule, { 7 | transport: Transport.RMQ, 8 | options: { 9 | urls: ['amqp://guest:guest@localhost:5672/hello'], 10 | queue: 'user-messages', 11 | queueOptions: { 12 | durable: false 13 | }, 14 | }, 15 | }); 16 | await app.listen(() => console.log('Microservice is listening')); 17 | } 18 | bootstrap(); 19 | -------------------------------------------------------------------------------- /microservices-app/test/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { Test, TestingModule } from '@nestjs/testing'; 2 | import { INestApplication } from '@nestjs/common'; 3 | import * as request from 'supertest'; 4 | import { AppModule } from './../src/app.module'; 5 | 6 | describe('AppController (e2e)', () => { 7 | let app: INestApplication; 8 | 9 | beforeEach(async () => { 10 | const moduleFixture: TestingModule = await Test.createTestingModule({ 11 | imports: [AppModule], 12 | }).compile(); 13 | 14 | app = moduleFixture.createNestApplication(); 15 | await app.init(); 16 | }); 17 | 18 | it('/ (GET)', () => { 19 | return request(app.getHttpServer()) 20 | .get('/') 21 | .expect(200) 22 | .expect('Hello World!'); 23 | }); 24 | }); 25 | -------------------------------------------------------------------------------- /microservices-app/test/jest-e2e.json: -------------------------------------------------------------------------------- 1 | { 2 | "moduleFileExtensions": ["js", "json", "ts"], 3 | "rootDir": ".", 4 | "testEnvironment": "node", 5 | "testRegex": ".e2e-spec.ts$", 6 | "transform": { 7 | "^.+\\.(t|j)s$": "ts-jest" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /microservices-app/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "exclude": ["node_modules", "test", "dist", "**/*spec.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /microservices-app/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "declaration": true, 5 | "removeComments": true, 6 | "emitDecoratorMetadata": true, 7 | "experimentalDecorators": true, 8 | "target": "es2017", 9 | "sourceMap": true, 10 | "outDir": "./dist", 11 | "baseUrl": "./", 12 | "incremental": true 13 | }, 14 | "exclude": ["node_modules", "dist"] 15 | } 16 | -------------------------------------------------------------------------------- /microservices-app/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "defaultSeverity": "error", 3 | "extends": ["tslint:recommended"], 4 | "jsRules": { 5 | "no-unused-expression": true 6 | }, 7 | "rules": { 8 | "quotemark": [true, "single"], 9 | "member-access": [false], 10 | "ordered-imports": [false], 11 | "max-line-length": [true, 150], 12 | "member-ordering": [false], 13 | "interface-name": [false], 14 | "arrow-parens": false, 15 | "object-literal-sort-keys": false 16 | }, 17 | "rulesDirectory": [] 18 | } 19 | -------------------------------------------------------------------------------- /package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "requires": true, 3 | "lockfileVersion": 1, 4 | "dependencies": { 5 | "@nestjs/cqrs": { 6 | "version": "6.1.0", 7 | "resolved": "https://registry.npmjs.org/@nestjs/cqrs/-/cqrs-6.1.0.tgz", 8 | "integrity": "sha512-J1csaa2LdodZtwXOoYNcnqvFzk+G3RAR+G0N8k1/dlP7GvDJT3OakS2YXPiOSl7fEMOD40eS4+9sQMs8xqiegw==" 9 | } 10 | } 11 | } 12 | --------------------------------------------------------------------------------