Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/m-sardari/rabbitmq
RabbitMQ is a messaging broker - an intermediary for messaging
https://github.com/m-sardari/rabbitmq
rabbit rabbitmq rabbitmq-client rabbitmq-consumer rabbitmq-producer rabbitmq-server
Last synced: about 2 months ago
JSON representation
RabbitMQ is a messaging broker - an intermediary for messaging
- Host: GitHub
- URL: https://github.com/m-sardari/rabbitmq
- Owner: M-Sardari
- License: mit
- Created: 2022-11-28T13:33:33.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2022-12-27T19:51:47.000Z (about 2 years ago)
- Last Synced: 2024-10-28T23:12:53.944Z (3 months ago)
- Topics: rabbit, rabbitmq, rabbitmq-client, rabbitmq-consumer, rabbitmq-producer, rabbitmq-server
- Language: TypeScript
- Homepage:
- Size: 120 KB
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Description
RabbitMQ is a messaging broker - an intermediary for messaging. It gives your applications a common platform to send and receive messages, and your messages a safe place to live until received.
You can to use gadin-rabbit package easily and setup it.
## Usage
### Step 1: Installation
```sh
npm install gadin-rabbit
```wait for the installation to finish.
### Step 2: Module initialization
You've added below code in your root module:
```ts
@Module({
imports: [
RmqModule.register({
uri: 'amqp://guest:guest@localhost:5672',
name : "services",
wait : true ,
timeout : 20000,
type : 'topic',
prefetchCount : 10
}),
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {
}
```### Notice
1. The name, wait, timeout, type and prefetchCount are optional.
2. Default value of type is topic.### Step 3: Use in Services
You've to add these decorators above the functions:
#### Subscribe
If the return value of your function is void, then you have to use this method:```ts
@Subscribe({
routingKey: 'user.add',
queue: 'user-add',
})
addUser(objUser:any) : void
{
// add user...
}
```#### Rpc
If the return value of your function is not void, then you have to use this method:```ts
@Rpc({
routingKey: 'user.get',
queue: 'user-get',
})
getUser(id:number) : User
{
// get user...
}
```### Notice
You've to inject RmqService in your service and use rabbit methods like below:
```ts
@Injectable()
export class AppService {
constructor(private broker: RmqService) {
}
}
```If you want consume your messages should be use these decorators:
#### publish
If you want to call void message, then you've to use this way:```ts
await this.broker.publish('user.add', payload);
```#### request
If you want to call don't void message, then you've to use this way:```ts
return await this.broker.request({ routingKey, payload, timeout });
```### Hint
Import RmqModule, RmqService, Rpc and Subscribe from the gadin-rabbit## Author
[Mohammad Sardari](mailto:[email protected])## License
[MIT License](./LICENCE)