https://github.com/restuwahyu13/node-rabbitmq-rpc
Example rabbitmq rpc pattern using messaging pattern (Request & Reply)
https://github.com/restuwahyu13/node-rabbitmq-rpc
message-broker node rabbitmq rpc
Last synced: 2 months ago
JSON representation
Example rabbitmq rpc pattern using messaging pattern (Request & Reply)
- Host: GitHub
- URL: https://github.com/restuwahyu13/node-rabbitmq-rpc
- Owner: restuwahyu13
- Created: 2023-02-25T11:30:54.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2023-02-26T05:13:07.000Z (about 2 years ago)
- Last Synced: 2025-01-03T17:51:40.922Z (4 months ago)
- Topics: message-broker, node, rabbitmq, rpc
- Language: TypeScript
- Homepage:
- Size: 17.2 MB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# RABBITMQ RPC (Request & Reply Pattern)
Check this tutorial about rpc queue using **rabbitmq** [here](https://www.rabbitmq.com/tutorials/tutorial-six-python.html) and check this tutorial about messaging pattern request & reply [here](https://www.enterpriseintegrationpatterns.com/RequestReply.html), if you need tutorial about rabbitmq check my repo [here](https://github.com/restuwahyu13/node-rabbitmq), or if you need other example rpc pattern using go [here](https://github.com/restuwahyu13/golang-rabbitmq-rpc).
## Server RPC
```ts
import { faker } from '@faker-js/faker'
import { RabbitMQ, consumerOverwriteResponse } from './rabbitmq'const requestData: Record = {
id: faker.datatype.uuid(),
name: faker.name.fullName(),
country: faker.address.country(),
city: faker.address.city(),
postcode: faker.address.zipCode()
}const replyTo: consumerOverwriteResponse = {
data: requestData
}const rabbitmq: InstanceType = new RabbitMQ()
rabbitmq.consumerRpc('account', replyTo)process.on('SIGINT', function () {
console.log(`Terminated process: ${process.pid} successfully`)
process.exit(0)
})setInterval(() => console.log('...........................'), 3000)
```## Client RPC
```ts
import { faker } from '@faker-js/faker'
import { RabbitMQ, rpcResponse } from './rabbitmq'const requestData: Record = {
id: faker.datatype.uuid(),
name: faker.name.fullName(),
country: faker.address.country(),
city: faker.address.city(),
postcode: faker.address.zipCode()
}const rabbitmq: InstanceType = new RabbitMQ()
rabbitmq.publishRpc('account', requestData).then((value: rpcResponse) => {
console.log(JSON.parse(value.data))
})
```## Noted Important!
if queue name is not deleted like this image below, after consumers consuming data from queue, because there is problem with your consumers.
