Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alesanchezr/text-queue
https://github.com/alesanchezr/text-queue
Last synced: 13 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/alesanchezr/text-queue
- Owner: alesanchezr
- Created: 2021-08-05T16:50:59.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-08-05T17:32:36.000Z (over 3 years ago)
- Last Synced: 2024-10-04T02:21:13.078Z (about 1 month ago)
- Language: JavaScript
- Size: 37.1 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Text-Based-Queue
Extremelly simple text-based polling queue engine. Similar to RabbitMQ but simpler, text-based and unidirectional (polling protocol).
![Text Based Queue](https://github.com/alesanchezr/text-queue/blob/main/preview.png?raw=true)
## What is this for?
Is a simpler alternative to Socket.io with less restrictions.
- Some times using sockets is impossible because of security or network limitations.
- Faster than sockets
- Persistent (if option.create = false the queue history will never be deleted)## How to use
1. Initializing a new queue and dispatiching your first event:
```js
// initialize your dispatcher
const dispatcher = queue.dispatcher({ create: true, path: `./path/to/file.json` })//you can send any data as event payload
let data = { foo: "bar" }
// start enqueing/dispatching any events
dispatcher.enqueue("initilialized", data)// dispatch any other custom event you want
dispatcher.enqueue("send_email")
```2. Listening to incoming events from the queue:
```js
//initialize your queue listener
const listener = queue.listener({ path: `./path/to/file.json` })
// when a new event is added to the queue, the onPull method will be triggered
// and you receive the incoming event name and the payload/data
listener.onPull((e) => console.log(`Incoming event with name ${e.name}`, e.data))
// if the queue file gets deleted or reseted we can also listen and receive any queued events
listener.onReset((e) => console.log(`Incoming event with name ${e.name}`, e.data))
```## Options and Settings
### For the queue dispatcher
```js
queue.dispatcher({
create: true, // Will create a new queue every time its initialized, defaults to false
path: `./path/to/file.json` // path to the file that will store the queue
})
```