cqi-core v0.4.1
CQI stands for Common Queue Interface, inspired by CGI.
CQI is a simple and extensible framework to develop queue worker application. It listens message from a queue, and dispatch the messages to an another process through the standard I/O.
The following code listens SQS queue, and executes application.sh for each message. application.sh inputs message body via STDIN, and return the exit code 0 if succeeded.
import { CQI } from '../src/index'
const cqi = CQI.instance
const listener = CQI.factory.listeners.create('sqs', {
region: 'your-region-1', // Your region
queueUrl: 'https://sqs.your-region-1.amazonaws.com/ACCOUNT/QUEUE', // Your queueu URL
})
const dispatcher = CQI.factory.dispatchers.create('exec', {
programFilePath: 'application.sh'
})
cqi.runDefaultContainer(listener, dispatcher)Component Types
Listener
Listener receive messages from a queue, and passes them to the dispatcher.
arrayListener to dispatch smessages as string array. (for debugging)replListener to dispatch message input from console. (for debugging)sqsAmazon SQS listener.
Dispatcher
Dispatcher passes a queue message from listener to the processer, and decide if successfully consumed.
EchoDispatcherOnly echo the message.ExecDispatcherCGI style. Starting a new process for each message.StdioDispatherServer style. Single process receives messages as lines from STDIN.
ExecDispatcher starts new process for each message, and writes the JSON to STDIN. If the exit status is 0, the message processed successfully.
StdioDispather starts a new process at first, and write each message as a JSON line to STDIN. The process outputs blank line if successfully consumed. Not blank line assumed an error message.
Container
Container joins listener and dispather. There is only one Container.