Skip to content

thinblock/notifications-microservice

Repository files navigation

Notifications-Microservice

ThinBlock's Notifications MicroService is built on restify framework. It depends on NodeJS server v8.11.2 and tests are written with chai and runner is mocha. The database is MongoDb with mongoose ORM. We use TypeScript langauge to write strongly typed code which has less chances of breaking and better intellisense support in VS Code.

Installation

We use yarn to install the packages. Do

 yarn install

in the project's directory. After installing you need to set up environment variables. In Unix based systems you can do:

 export TB_NOTIFICATION_MS_REDIS_DB_STRING="Redis connection string here"

Contact the collaborators to get remote db string and node string.

Starting Development Server

To start the development server do

 yarn start

To watch the typescript files you can use nodemon, if you don't have nodemon installed you can install it via

 yarn add nodemon -g
 // now start watching, do this in project's directory
 nodemon

Event Type

This microservice on receiving SNS-Event (NOTIFY_CLIENT_APP) with SNS Message as JSON String that have the following keys:

  • jobId (required)
  • event (what kind of event to notify the end user: required)
  • data (data to be sent along with event: optional)

creates a background task to notify the end client app. It basically gets the type of notification from the Jobs DB and acts upon it.

File Structure

 - app
 	- interfaces (interfaces gives better intellisense and strong type)
	 	- utils (typescript interfaces for utils goes here)
		 models.ts (interfaces for model goes here)
	 - middlewares (middlewares go here)
	 - models (add models here, it should contain .model at the end of the file)
	 - modules
	 	- some_module (modules go here, it should be abstracted as domain)
		 	- some_module.listener.ts
			 - some_module.route.ts
			 - some_module.unit.spec.ts
 - config (Config related stuff)
 - scripts (deployment/packaging related stuff)
 - types (When types for certain package doesn't exist, add that package here)
 - utils (Utilities and helpers
 server.ts
 package.json

Adding New Package

When adding new libraries/packages, you should install its types too. If its types don't exist then you should add that package to types/types.ts

 yarn add some-package @types/some-package

Testing

Every module should be battle tested so that we avoid any bugs. We have CI integrated, whenever introducing new feature. We'll run the tests before merging any stuff. You should make sure all tests pass. You can run tests by doing

 yarn run test

It'll run all the tests, if you want to run your specific test. You can do this

 describe.only()
 or
 it.only()

About

ThinBlock's Notifications MicroService using Restify Framework

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published