Skip to main content
Version: v1

Installation

Requirements#

  • Node.js version >= 12.13.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

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/"

And then install the package.

npm i --save @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 autoloaded
โ”œโ”€โ”€ 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 autoloaded from here
โ”‚ โ”œโ”€โ”€ topics/
โ”‚ โ””โ”€โ”€ subscription.service.js <-- this is the entrypoint for the service
โ””โ”€โ”€ package.json

Required Environment Variables#

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

.env
PUBSUB_ROOT_DIR=/path/to/your/pubsub/directory # this can be a relative path to process cwd
GOOGLE_APPLICATION_CREDENTIALS=/path/to/gcp-project-83d5537a8388-key.json
GOOGLE_CLOUD_PUB_SUB_PROJECT_ID=gcp-project-id
CLI ArgumentEnv VariableDescription
root-dirPUBSUB_ROOT_DIRmust be the path to your project's pubsub directory. This module only works with .js files, so if you are writing your code in typescript, you must set this variable to the pubsub directory in your project's build directory.
google-application-credentialsGOOGLE_APPLICATION_CREDENTIALSsee https://cloud.google.com/docs/authentication/getting-started#creating_a_service_account to generate this
project-idGOOGLE_CLOUD_PUB_SUB_PROJECT_IDname of the project in Google Cloud Platform
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

|

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.