{"_id":"@briohr/broker","_rev":"2-71769501e19d053a7152bc3892962eb3","name":"@briohr/broker","dist-tags":{"latest":"0.0.0-0f43396"},"versions":{"0.0.0-0f43396":{"name":"@briohr/broker","version":"0.0.0-0f43396","keywords":["nestjs"],"author":{"name":"Benjamin Bellantonio"},"license":"MIT","_id":"@briohr/broker@0.0.0-0f43396","maintainers":[{"name":"nabil-oudghiri","email":"nabil.oudghiri@briohr.com"},{"name":"hantzesudarma","email":"hantze@briohr.com"}],"homepage":"https://github.com/BrioHR/broker","dist":{"shasum":"2dbebfdbb0ee9d99c2ca5ae1618d06a483f6514c","tarball":"https://registry.npmjs.org/@briohr/broker/-/broker-0.0.0-0f43396.tgz","fileCount":51,"integrity":"sha512-ywmq3ZgwUAWsN24KqMwxwhNXQlBl07GaOFNvTLwGLTT1JzZzL5sB40ekmZJQklPcbT1iXtshY2OAW4kltSy/3Q==","signatures":[{"sig":"MEUCIQDUP7KuMIekpc13GzVupM52gmdf8FIqs1FUmPEolNwdpgIgCoviY7ybmQPs1b9sZLNMYq/LhNqa4k6pT+tG1I07D2Q=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":36340},"jest":{"rootDir":"src","testRegex":".spec.ts$","transform":{"^.+\\.(t|j)s$":"ts-jest"},"testEnvironment":"node","coverageDirectory":"../coverage","moduleFileExtensions":["js","json","ts"]},"main":"dist/index.js","scripts":{"build":"tsc","prepare":"npm run build","publish":"npm run build && npm publish","start:dev":"tsc --watch"},"_npmUser":{"name":"hantzesudarma","email":"hantze@briohr.com"},"prettier":"@briohr/prettier-config-briohr","_npmVersion":"6.14.18","description":"NestJS module to produce and consume messages with the broker of your choice. From the BrioHR team.","directories":{},"_nodeVersion":"14.21.3","dependencies":{"amqplib":"^0.10.3","@nestjs-plus/discovery":"^2.0.2","amqp-connection-manager":"^3.9.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"rxjs":"^7.1.0","eslint":"^8.29.0","ts-node":"8.1.0","prettier":"^1.17.0","typescript":"^4.9.4","@types/node":"11.13.4","@nestjs/core":"^9.2.1","@nestjs/common":"^9.2.1","tsconfig-paths":"3.8.0","reflect-metadata":"^0.1.13","@briohr/prettier-config-briohr":"^1.0.0","@briohr/eslint-config-briohr-backend":"^1.0.0"},"peerDependencies":{"@nestjs/common":"^9.2.1"},"_npmOperationalInternal":{"tmp":"tmp/broker_0.0.0-0f43396_1741749946111_0.39723992007358877","host":"s3://npm-registry-packages-npm-production"}}},"time":{"created":"2025-03-12T03:25:46.025Z","modified":"2025-10-23T07:58:32.380Z","0.0.0-0f43396":"2025-03-12T03:25:46.301Z"},"author":{"name":"Benjamin Bellantonio"},"license":"MIT","homepage":"https://github.com/BrioHR/broker","keywords":["nestjs"],"description":"NestJS module to produce and consume messages with the broker of your choice. From the BrioHR team.","maintainers":[{"email":"nabil.oudghiri@briohr.com","name":"nabil-oudghiri"},{"email":"hantze@briohr.com","name":"hantzesudarma"},{"email":"julien@briohr.com","name":"julien_briohr"}],"readme":"## Description\n\n[NestJS](https://github.com/nestjs/nest) module to produce and consume messages with the broker of your choice.\n\nFrom the [BrioHR](http://briohr.com) team.\n\nDependencies :\n\n- [@nestjs-plus/discovery](https://www.npmjs.com/package/@nestjs-plus/discovery)\n- [amqplib](https://www.npmjs.com/package/amqplib)\n\nFor now these brokers are implemented :\n\n- RabbitMQ : `BROKER_TYPE_RABBIT`\n\nFuture brokers to implement :\n\n- Apache Kafka : `BROKER_TYPE_KAFKA`\n\n## Installation\n\n```bash\n$ npm i --save @briohr/nest-broker\n```\n\n## Usage\n\nImport `NestBrokerModule`:\n\n```typescript\n@Module({\n  imports: [NestBrokerModule.register({\n    url: string, // url of your broker\n    type: BROKER_TYPE_RABBIT, // other types will be implemented\n    service: 'serviceName' // optional\n  })],\n  providers: [...],\n})\nexport class AppModule {}\n```\n\nInject `NestBrokerService`:\n\n```typescript\n@Injectable()\nexport class MyService {\n  constructor(private readonly nestBroker: NestBrokerService) {}\n}\n```\n\n## Async options\n\n```typescript\nNestBrokerModule.registerAsync({\n  imports: [ConfigModule],\n  useFactory: async (configService: ConfigService) => ({\n    url: configService.getString('BROKER_URL'),\n    type: BROKER_TYPE_RABBIT,\n    service: 'serviceName',\n    logger: new MyLogger()\n  }),\n  inject: [ConfigService],\n}),\n```\n\n## API Spec\n\n#### nestBrokerService.publish(topic: string, content: {}): Promise<any>\n\nThe publish method produce a message in the specified topic.\n\n## Decorator\n\n#### @Subscribe(topic: string, prefetch = 0)\n\nUsed to register and subscribe a service method to a specified topic. **Only on NestJS services methods.**\n\n## Example\n\n### Producer\n\n```typescript\n@Controller()\nexport class AppController {\n  constructor(private nestBroker: NestBrokerService) {}\n\n  @Post(\"/employee\")\n  createEmployee(): Employee {\n    // handle your logic\n    const employee = this.employeeService.create({\n      id: 1,\n      name: \"Elliot Alderson\"\n    });\n\n    const testValue = 9999;\n\n    // when you are done just publish your message with the data you want\n    // (this is just an example)\n    if (employee && testValue > 0) {\n      this.nestBroker.publish(\"CREATE_EMPLOYEE\", {\n        id: employee.id,\n        name: employee.name,\n        testValue\n      });\n    }\n\n    return employee;\n  }\n}\n```\n\n### Consumer\n\n```typescript\n@Injectable()\nexport class AppService {\n  @Subscribe(\"CREATE_EMPLOYEE\")\n  processNewEmployee(messageBody): void {\n    // handle the CREATE_EMPLOYEE message\n    console.log(messageBody); // {id: 1, name: \"Elliot Alderson\", testValue: 9999}\n  }\n}\n```\n\nThe `NestBrokerModule` takes an `options` object:\n\n- `url` is a string, and this is the url to your broker\n- `type` is a constant from this module, so you can set the broker type\n- `service` is a string, and optional, it's used in case you have multiple service and you want to subscribe them all to the same topic (required for RabbitMQ)\n- `logger` is an instance of a custom NestJS Logger, and optional\n\n#### Informations about RabbitMQ implementation\n\nWhen you publish a message, it is sent to a fanout exchange.\n\nIn the background, this module use the `service` option to create specific queues for each consumers. And bind them to the exchange.\n\nThe prefetch option in the subscriber decorator is to allow RabbitMQ consume multiples messages at the same time.\n\n#### Informations about Apache Kafka implementation\n\nNot implemented.\n","readmeFilename":"README.md"}