@lifechurch/subserver
Subserver is a background server process for processing messages from Google Pub/Sub.
Usage
Install
yarn add @lifechurch/subserver @google-cloud/pubsub
Start
import Subserver from '@lifechurch/subserver';
import { handlers } from './handlers';
const handler = message => {
// perform some action
message.ack();
};
const config = {
subscribers: [
{
name: 'subscription',
queue: 'default',
handler: handler,
}
],
queue: 'default', // optional
keepAliveInterval: 1000 * 60 * 60 //optional
};
Subserver.start(config);
Configuration
Property | Type | Description |
---|---|---|
subscribers |
Array |
name : Name of the Subscriptionqueue : Queue to process the Subscription onhandler : Listener function to execute when a message is received |
queue |
String | Name of the queue to process the subscription on |
livenessPort |
Number | The port in which to run the liveness server (Default: 4000) |
Local Development
Below is a list of commands you will probably find useful.
yarn build
Bundles the package to the dist
folder.
The package is optimized and bundled with Rollup into multiple formats (CommonJS, UMD, and ES Module).
yarn test
Runs the test watcher (Jest) in an interactive mode. By default, runs tests related to files changed since the last commit.