tk-queue
v1.2.2
Published
```
Downloads
22
Readme
TechKids Edu Rabbit Queue
User guide
Connect
import { connect as tkQueueConnect } from 'tk-queue';
const queueUri = `amqp://${rabbitConfig.USERNAME}:${rabbitConfig.PASSWORD}@${rabbitConfig.HOST}:${rabbitConfig.PORT}`
tkQueueConnect(queueUri);
Producer
import { RbProducer } from 'tk-queue';
// Initialize
const rbUserProducer = RbProducer('user');
// Send message when connection is ready
rbUserProducer.send('upsert', <new user data>);
Consumer
// Initialize
import { RbConsumer } from 'tk-queue';
const rbUserConsumer = new RbConsumer(
"tk-lm",
"user",
(data) => new Promise((resolve, reject) => {
// Upsert user here
resolve();
}),
(_id) => new Promise((resolve, reject) => {
// Delete user here
resolve();
})
// Listen when connection is ready
rbUserConsumer.listen();
Note
Queue design:
- Some keywords:
- A producer is a user application that sends messages.
- A queue is a buffer that stores messages.
- A consumer is a user application that receives messages.
- An exchange is a very simple thing. On one side it receives messages from producers and the other side it pushes them to queues.
- Each service occupies one and only one queue, (e.g.
tk-lm-service
,tk-hr-service
,tk-crm
,...) - Each resource occupies one and only one exchange, (e.g.
course
,user
,registration
,...), has only one producer and multi consumer. - Related tutorial about how all that things work together: Read
Message format:
type
: Operation type (e.g.upsert
,delete
)data
: The udpateddata
If there is problem with message in queue, the team should treat it as very critical issuse, thus stop whatever they are doing to fix it
Developer guide
Develop
index.ts
: The whole lib
Publish
- Change version in package.json file:
{
"name": "tk-queue",
"version": "x.x.x",
...
}
Build
npm run build
Publish
npm publish