This is a template for a data microservice stores and retrieves entities.
Supported functionality:
- Deployment platforms: Standalone Process, Docker
- External APIs: Commandable HTTP, HTTP/REST, GRPC, Commandable GRPC
- Persistence: Memory, Flat Files, MongoDB, PosgreSQL, MySQL, SQLServer
- Health checks: Heartbeat, Status
- Consolidated logging: ElasticSearch
- Consolidated metrics: Prometheus
- Swagger: http://localhost:8080/swagger/index.html
There are no dependencies on other microservices.
- Communication Protocols:
- Client Libraries:
- API Reference
- Change Log
class EntityTypeV1 {
public static Unknown: string = "unknown";
public static Type1: string = "type1";
public static Type2: string = "type2";
public static Type3: string = "type3";
}
class EntityV1 implements IStringIdentifiable {
public id: string;
public site_id: string;
public type?: string;
public name?: string;
public content?: string;
}
interface IEntitiesClient {
getEntities(correlationId: string, filter: FilterParams, paging: PagingParams): Promise<DataPage<EntityV1>>;
getEntityById(correlationId: string, entityId: string): Promise<EntityV1>;
getEntityByName(correlationId: string, entityId: string): Promise<EntityV1>;
createEntity(correlationId: string, entity: EntityV1): Promise<EntityV1>;
updateEntity(correlationId: string, entity: EntityV1): Promise<EntityV1>;
deleteEntityById(correlationId: string, entityId: string): Promise<EntityV1>;
}
Get the microservice source from BitBucket:
git clone git@bitbucket.org:entinco/eic-templates-node.git
cd service-data-pipservices
Get docker image for the microservice:
docker pull eic-templates/service-data-pipservices:latest
The microservice can be configured using the environment variables:
- DATADOG_ENABLED - turn on DataDog loggers and metrics
- DTAT_DOG_PROTOCOL - (optional) connection protocol: http or https (default: https)
- DATADOG_URI - (optional) resource URI or connection string with all parameters in it
- DATADOG_HOST - (optional) host name or IP address (default: api.datadoghq.com)
- DATADOG_PORT - (optional) port number (default: 443)
- DATADOG_ACCRSS_KEY - DataDog client api key
- ELASTICSEARCH_LOGGING_ENABLED - turn on Elasticsearch logs and metrics
- ELASTICSEARCH_PROTOCOL - connection protocol: http or https
- ELASTICSEARCH_SERVICE_URI - resource URI or connection string with all parameters in it
- ELASTICSEARCH_SERVICE_HOST - host name or IP address
- ELASTICSEARCH_SERVICE_PORT - port number
- FILE_ENABLED - turn on file persistence. Keep it undefined to turn it off
- FILE_PATH - file path where persistent data shall be stored (default: ../data/id_records.json)
- GRPC_ENABLED - turn on GRPC endpoint
- GRPC_COMMANDABLE_ENABLED - turn on Commandable GRPC (default: GRPC service)
- GRPC_PORT - GRPC port number (default: 8090)
- MEMORY_ENABLED - turn on in-memory persistence. Keep it undefined to turn it off
- MONGO_ENABLED - turn on MongoDB persistence. Keep it undefined to turn it off
- MONGO_SERVICE_URI - URI to connect to MongoDB. When it's defined other database parameters are ignored
- MONGO_SERVICE_HOST - MongoDB hostname or server address
- MONGO_SERVICE_PORT - MongoDB port number (default: 3360)
- MONGO_DB - MongoDB database name (default: app)
- MONGO_COLLECTION - MongoDB collection (default: id_records)
- MONGO_USER - MongoDB user login
- MONGO_PASS - MongoDB user password
- MYSQL_ENABLED - turn on MySql persistence. Keep it undefined to turn it off
- MYSQL_JSON_ENABLED - turn on JSON MySql persistence. Keep it undefined to turn it off
- MYSQL_URI - URI to connect to MySql. When it's defined other database parameters are ignored
- MYSQL_HOST - MySql hostname or server address
- MYSQL_PORT - MySql port number (default: 3306)
- MYSQL_DB - MySql database name (default: test)
- MYSQL_USER - MySql user login
- MYSQL_PASSWORD - MySql user password
- POSTGRES_ENABLED - turn on PostgreSQL persistence. Keep it undefined to turn it off
- POSTGRES_JSON_ENABLED - turn on JSON PostgreSQL persistence. Keep it undefined to turn it off
- POSTGRES_SERVICE_URI - URI to connect to PostgreSQL. When it's defined other database parameters are ignored
- POSTGRES_SERVICE_HOST - PostgreSQL hostname or server address
- POSTGRES_SERVICE_PORT - PostgreSQL port number (default: 5432)
- POSTGRES_DB - PostgreSQL database name (default: app)
- POSTGRES_TABLE - PostgreSQL table (default: id_records)
- POSTGRES_USER - PostgreSQL user login
- POSTGRES_PASS - PostgreSQL user password
- PUSHGATEWAY_METRICS_ENABLED - turn on pushgetway for prometheus
- PUSHGATEWAY_PROTOCOL - connection protocol: http or https
- PUSHGATEWAY_METRICS_SERVICE_URI - resource URI or connection string with all parameters in it
- PUSHGATEWAY_METRICS_SERVICE_HOST - host name or IP address
- PUSHGATEWAY_METRICS_SERVICE_PORT - port number
- SQLSERVER_ENABLED - turn on SQL Server persistence. Keep it undefined to turn it off
- SQLSERVER_JSON_ENABLED - turn on JSON SQL Server persistence. Keep it undefined to turn it off
- SQLSERVER_SERVICE_URI - URI to connect to SQL Server. When it's defined other database parameters are ignored
- SQLSERVER_SERVICE_HOST - SQL Server hostname or server address
- SQLSERVER_SERVICE_PORT - SQL Server port number (default: 1433)
- SQLSERVER_DB - SQL Server database name (default: app)
- SQLSERVER_TABLE - SQL Server table (default: id_records)
- SQLSERVER_USER - SQL Server user login
- SQLSERVER_PASS - SQL Server user password
- HTTP_ENABLED - turn on HTTP endpoint
- HTTP_PORT - HTTP port number (default: 8080)
- SWAGGER_ROUTE - the path where the swagger service will be available
- SWAGGER_NAME - the header name of swagger service
- SWAGGER_DESCRIPTION - the text description of swagger service
Start the microservice as process:
node ./bin/main
Run the microservice in docker: Then use the following command:
./run.ps1
Launch the microservice with all infrastructure services using docker-compose:
docker-compose -f ./docker/docker-compose.yml
Install the client NPM package as
npm install client-entities-node
Inside your code get the reference to the client library
import { EntitiesHttpClientV1 } from 'client-entities-node';
Instantiate the client
// Create the client instance
let client = new EntitiesHttpClientV1();
Define client configuration parameters.
// Client configuration
let httpConfig = ConfigParams.fromTuples(
"connection.protocol", "http",
"connection.host", "localhost",
"connection.port", 3000
);
client.configure(httpConfig);
Connect to the microservice
// Connect to the microservice
await client.open("123");
Create a new entity
let entity: EntityV1 = {
id: IdGenerator.nextId(),
type: EntityTypeV1.Type1,
name: 'Entity #1',
content: 'Bla bla bla'
};
entity = await client.create("123", entity);
console.log("Created entity: " + entity);
Retrive entities with Type1
let page = await client.getData("123",
FilterParams.fromTuples(
'type', EntityTypeV1.Type1
),
new PagingParams(0, 100)
);
console.log("Retrieved entities: " + page.data);
For development you shall install the following prerequisites:
- Node.js
- Visual Studio Code or another IDE of your choice
- Docker
- Typescript
Install dependencies:
npm install
Compile the microservice:
tsc
Before running tests launch infrastructure services and required microservices:
docker-compose -f ./docker-compose.dev.yml
Run automated tests:
npm test
Run automated benchmarks:
npm run benchmark
Generate API documentation:
./docgen.ps1
Before committing changes run dockerized build and test as:
./build.ps1
./test.ps1
./package.ps1
./run.ps1
./clean.ps1
This microservice was created by and is currently maintained by Enterprise Innovation Consulting.