-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f84377f
Showing
31 changed files
with
933 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# Typescript v1 declaration files | ||
typings/ | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variables file | ||
.env | ||
|
||
# upload | ||
uploads/ | ||
|
||
.DS_Store | ||
.gulp-cache | ||
src/test | ||
.vscode | ||
logs/ | ||
*.thrift | ||
*.sql |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"singleQuote": true, | ||
"trailingComma": "all" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2018 KnowYourself | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
|
||
# Nestjs Rabbitmq | ||
Rabbitmq component for NestJs. | ||
|
||
|
||
### Installation | ||
|
||
**Yarn** | ||
```bash | ||
yarn add nestjs-rabbitmq | ||
``` | ||
|
||
**NPM** | ||
```bash | ||
npm install nestjs-rabbitmq --save | ||
``` | ||
|
||
### Getting Started | ||
Let's import the RabbitMqModule in `app.module.ts` | ||
|
||
```typescript | ||
import { Module } from '@nestjs/common'; | ||
import { RabbitMqModule} from 'nestjs-rabbitmq' | ||
|
||
@Module({ | ||
imports: [ | ||
RabbitMqModule.forRoot(options) | ||
], | ||
}) | ||
export class AppModule {} | ||
``` | ||
With Async | ||
```typescript | ||
import { Module } from '@nestjs/common'; | ||
import { RabbitMqModule} from 'nestjs-rabbitmq' | ||
|
||
@Module({ | ||
imports: [ | ||
RabbitMqModule.forRootAsync({ | ||
useFactory: (configService: ConfigService) => configService.get('rabbitmq'), // or use async method | ||
//useFactory: async (configService: ConfigService) => configService.get('rabbitmq'), | ||
inject:[ConfigService] | ||
}), | ||
], | ||
}) | ||
export class AppModule {} | ||
``` | ||
Options | ||
```typescript | ||
interface RabbitMqModuleOptions { | ||
user?: string, //Default guest | ||
passwd?: string, //Default guest | ||
host?: string, //Default localhost | ||
port?: number //Default 5672 | ||
} | ||
``` | ||
That's it! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './rabbitmq.interface'; | ||
export * from './rabbitmq.module'; | ||
export * from './rabbitmq.service'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
"use strict"; | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__export(require("./rabbitmq.module")); | ||
__export(require("./rabbitmq.service")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { RabbitMqModuleOptions, RabbitMqModuleAsyncOptions } from "./rabbitmq.interface"; | ||
import * as amqp from 'amqp-connection-manager'; | ||
export declare const createClient: () => { | ||
provide: symbol; | ||
useFactory: (options: RabbitMqModuleOptions) => amqp.AmqpConnectionManager; | ||
inject: symbol[]; | ||
}; | ||
export declare const createAsyncClientOptions: (options: RabbitMqModuleAsyncOptions) => { | ||
provide: symbol; | ||
useFactory: (...args: any[]) => RabbitMqModuleOptions | Promise<RabbitMqModuleOptions>; | ||
inject: any[]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const rabbitmq_constants_1 = require("./rabbitmq.constants"); | ||
const amqp = require("amqp-connection-manager"); | ||
exports.createClient = () => ({ | ||
provide: rabbitmq_constants_1.RABBITMQ_CLIENT, | ||
useFactory: (options) => { | ||
return amqp.connect([`amqp://${options.user || 'guest'}:${options.passwd || 'guest'}@${options.host || 'localhost'}:${options.port || 5672}`]); | ||
}, | ||
inject: [rabbitmq_constants_1.RABBITMQ_MODULE_OPTIONS] | ||
}); | ||
exports.createAsyncClientOptions = (options) => ({ | ||
provide: rabbitmq_constants_1.RABBITMQ_MODULE_OPTIONS, | ||
useFactory: options.useFactory, | ||
inject: options.inject | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export declare const RABBITMQ_MODULE_OPTIONS: unique symbol; | ||
export declare const RABBITMQ_CLIENT: unique symbol; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.RABBITMQ_MODULE_OPTIONS = Symbol('RABBITMQ_MODULE_OPTIONS'); | ||
exports.RABBITMQ_CLIENT = Symbol('RABBITMQ_CLIENT'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { ModuleMetadata } from "@nestjs/common/interfaces"; | ||
export interface RabbitMqModuleOptions { | ||
user?: string; | ||
passwd?: string; | ||
host?: string; | ||
port?: number; | ||
} | ||
export interface RabbitMqModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> { | ||
useFactory?: (...args: any[]) => RabbitMqModuleOptions | Promise<RabbitMqModuleOptions>; | ||
inject?: any[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { DynamicModule } from '@nestjs/common'; | ||
import { RabbitMqModuleOptions, RabbitMqModuleAsyncOptions } from './rabbitmq.interface'; | ||
export declare class RabbitMqModule { | ||
static forRoot(options: RabbitMqModuleOptions): DynamicModule; | ||
static forRootSync(options: RabbitMqModuleAsyncOptions): DynamicModule; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
"use strict"; | ||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; | ||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); | ||
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; | ||
return c > 3 && r && Object.defineProperty(target, key, r), r; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var RabbitMqModule_1; | ||
const common_1 = require("@nestjs/common"); | ||
const rabbitmq_constants_1 = require("./rabbitmq.constants"); | ||
const rabbitmq_service_1 = require("./rabbitmq.service"); | ||
const rabbitmq_client_provider_1 = require("./rabbitmq-client.provider"); | ||
let RabbitMqModule = RabbitMqModule_1 = class RabbitMqModule { | ||
static forRoot(options) { | ||
return { | ||
module: RabbitMqModule_1, | ||
providers: [ | ||
rabbitmq_client_provider_1.createClient(), | ||
{ | ||
provide: rabbitmq_constants_1.RABBITMQ_MODULE_OPTIONS, | ||
useValue: options | ||
} | ||
], | ||
exports: [rabbitmq_service_1.RabbitMqService] | ||
}; | ||
} | ||
static forRootSync(options) { | ||
return { | ||
module: RabbitMqModule_1, | ||
providers: [ | ||
rabbitmq_client_provider_1.createClient(), | ||
rabbitmq_client_provider_1.createAsyncClientOptions(options), | ||
], | ||
exports: [rabbitmq_service_1.RabbitMqService] | ||
}; | ||
} | ||
}; | ||
RabbitMqModule = RabbitMqModule_1 = __decorate([ | ||
common_1.Global(), | ||
common_1.Module({ | ||
providers: [rabbitmq_service_1.RabbitMqService], | ||
exports: [rabbitmq_service_1.RabbitMqService] | ||
}) | ||
], RabbitMqModule); | ||
exports.RabbitMqModule = RabbitMqModule; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import * as amqp from 'amqp-connection-manager'; | ||
export declare class RabbitMqService { | ||
private readonly client; | ||
constructor(client: amqp.AmqpConnectionManager); | ||
getClient(): amqp.AmqpConnectionManager; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
"use strict"; | ||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; | ||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); | ||
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; | ||
return c > 3 && r && Object.defineProperty(target, key, r), r; | ||
}; | ||
var __metadata = (this && this.__metadata) || function (k, v) { | ||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); | ||
}; | ||
var __param = (this && this.__param) || function (paramIndex, decorator) { | ||
return function (target, key) { decorator(target, key, paramIndex); } | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const common_1 = require("@nestjs/common"); | ||
const rabbitmq_constants_1 = require("./rabbitmq.constants"); | ||
const amqp = require("amqp-connection-manager"); | ||
let RabbitMqService = class RabbitMqService { | ||
constructor(client) { | ||
this.client = client; | ||
} | ||
getClient() { | ||
return this.client; | ||
} | ||
}; | ||
RabbitMqService = __decorate([ | ||
common_1.Injectable(), | ||
__param(0, common_1.Inject(rabbitmq_constants_1.RABBITMQ_CLIENT)), | ||
__metadata("design:paramtypes", [Object]) | ||
], RabbitMqService); | ||
exports.RabbitMqService = RabbitMqService; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./dist"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
"use strict"; | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
exports.__esModule = true; | ||
__export(require("./dist")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './dist' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './rabbitmq.interface' | ||
export * from './rabbitmq.module' | ||
export * from './rabbitmq.service' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { RabbitMqModuleOptions, RabbitMqModuleAsyncOptions } from "./rabbitmq.interface"; | ||
import { RABBITMQ_CLIENT, RABBITMQ_MODULE_OPTIONS } from './rabbitmq.constants'; | ||
import * as amqp from 'amqp-connection-manager' | ||
export const createClient = () => ({ | ||
provide: RABBITMQ_CLIENT, | ||
useFactory:(options: RabbitMqModuleOptions) => { | ||
return amqp.connect([`amqp://${options.user || 'guest'}:${options.passwd || 'guest'}@${options.host || 'localhost'}:${options.port || 5672}`]) | ||
}, | ||
inject:[RABBITMQ_MODULE_OPTIONS] | ||
}) | ||
|
||
export const createAsyncClientOptions = (options: RabbitMqModuleAsyncOptions) => ({ | ||
provide: RABBITMQ_MODULE_OPTIONS, | ||
useFactory: options.useFactory, | ||
inject: options.inject | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const RABBITMQ_MODULE_OPTIONS = Symbol('RABBITMQ_MODULE_OPTIONS') | ||
export const RABBITMQ_CLIENT = Symbol('RABBITMQ_CLIENT') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { ModuleMetadata } from "@nestjs/common/interfaces"; | ||
|
||
export interface RabbitMqModuleOptions { | ||
user?: string, | ||
passwd?: string, | ||
host?: string, | ||
port?: number | ||
} | ||
|
||
export interface RabbitMqModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> { | ||
useFactory?: (...args: any[]) => RabbitMqModuleOptions | Promise<RabbitMqModuleOptions>, | ||
inject?: any[]; | ||
} |
Oops, something went wrong.