Skip to main content
Version: v2

Installation

Requirements#

  • Node.js version >= 12.22.0 or above (which can be checked by running node -v). You can use nvm for managing multiple Node versions on a single machine installed

Install#

From NPM#

npm

npm i --save @honestfoodcompany/pubsub

Or

yarn add @honestfoodcompany/pubsub

From Github Package Repository#

We also publish to Github Package Repository as @deliveryhero/pubsub. To install from there, first add this to your .npmrc:

@deliveryhero:registry="https://npm.pkg.github.com/"

Or for .yarnrc:

npmScopes:
deliveryhero:
npmRegistryServer: 'https://npm.pkg.github.com/'

And then install the package.

npm i --save @deliveryhero/pubsub

OR

yarn add @deliveryhero/pubsub

Project structure#

The framework expects that you've created a pubsub directory in your project with the following structure:

โ”œโ”€โ”€ .env <-- this should be in your project root directory and will be auto-loaded
โ”œโ”€โ”€ pubsub/ <-- this can be anywhere and named anything (defined in .env as PUBSUB_ROOT_DIR)
โ”‚ โ”œโ”€โ”€ subscriptions/ <-- any files ending with a `.sub.js` ext will be auto-loaded from here
โ”‚ โ”œโ”€โ”€ topics/
โ”‚ โ””โ”€โ”€ subscription.service.js <-- this is the entrypoint for the service
โ””โ”€โ”€ package.json

Environment Variables/CLI Args#

The framework expects the following environment variables. They can be added to the .env file or passed through CLI args.

CLI ArgumentEnv VariableDescription
root-dirPUBSUB_ROOT_DIRmust be the path to your project's pubsub directory.
google-application-credentialsGOOGLE_APPLICATION_CREDENTIALSsee https://cloud.google.com/docs/authentication/getting-started#creating_a_service_account to generate this
project-idGOOGLE_CLOUD_PROJECTthe project-id in Google Cloud Platform
labelsGOOGLE_CLOUD_LABELSLabels in stringified JSON format
server-portPUBSUB_SERVER_PORTPORT at which the pubsub should run the server at
health-serverPUBSUB_HEALTH_SERVERIf value assigned is true this would run a server showing health state and return 500 if not healthy

Read more in CLI docs

What next?#

  1. Once the directory structure has been defined and environment variables set
  2. Then you can create subscriptions and topics
  3. Initialize your database connection, define project-level subscription defaults, and register subscriptions in the Subscription Service.
  4. After a service has been created, use the CLI to start the subscriptions server.