Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/leocode/pg-message-queue
Simple MQ/PubSub implementation based on PostgreSQL.
https://github.com/leocode/pg-message-queue
Last synced: 10 days ago
JSON representation
Simple MQ/PubSub implementation based on PostgreSQL.
- Host: GitHub
- URL: https://github.com/leocode/pg-message-queue
- Owner: leocode
- Created: 2021-10-12T07:55:48.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2022-01-07T13:23:00.000Z (almost 3 years ago)
- Last Synced: 2023-08-19T06:39:31.228Z (over 1 year ago)
- Language: TypeScript
- Homepage:
- Size: 157 KB
- Stars: 3
- Watchers: 12
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# PG Message Queue (proof of concept, work in progress)
Simple MQ/PubSub implementation based on PostgreSQL.
## Install
```
npm i -s ...
```
or
```
yarn add ...
```## Usage
### Publisher
```typescript
import { createClient } from 'pg-queue';type Order = {
products: number[],
userId: number,
};(async () => {
const client = await createClient({
host: '127.0.0.1',
port: 5432,
user: 'postgres',
password: 'postgres',
database: 'database_name',
});const topic = await client.provideTopic('order.created');
await client.publish(topic, {
data: {
products: [4345, 543, 5623],
userId: 3242
},
headers: {}
});
})();
```### Consumer
```typescript
import { createClient } from 'pg-queue';type Order = {
products: number[],
userId: number,
};(async () => {
const client = await createClient({
host: '127.0.0.1',
port: 5432,
user: 'postgres',
password: 'postgres',
database: 'database_name',
});const topic = await client.provideTopic('order.created');
const subscription = await client.provideSubscription(topic, 'order.created.inventory_check');await client.subscribe(subscription, async message => {
// 💥🚀
});
})();
```## TODO/Ideas
1. Deadletter
2. Message ordering
3. Optional removing messages from db
4. Parameterized messages ordering / priority