Persister Configuration
Persister Service persists data in database in async manner providing very low latency. The queries which has to be used to insert/update data in database are written in yaml file. The values which has to be inserted are extracted from the json using jsonPaths defined in the same yaml configuration. Below is an sample configuration which inserts data in couple of tables.
serviceMaps:
serviceName: pgr-services
mappings:
- version: 1.0
description: Persists pgr service request in tables
fromTopic: save-pgr-request
isTransaction: true
queryMaps:
- query: INSERT INTO eg_pgr_service_v2(id, tenantid, additionaldetails, createdby, createdtime, lastmodifiedby, lastmodifiedtime) VALUES (?, ?, ?, ?, ?, ?, ?);
basePath: service
jsonMaps:
- jsonPath: $.service.id
- jsonPath: $.service.tenantId
- jsonPath: $.service.additionalDetail
type: JSON
dbType: JSONB
- jsonPath: $.service.auditDetails.createdBy
- jsonPath: $.service.auditDetails.createdTime
- jsonPath: $.service.auditDetails.lastModifiedBy
- jsonPath: $.service.auditDetails.lastModifiedTime
- query: INSERT INTO eg_pgr_address_v2(id, tenantid, parentid, doorno, plotno, buildingname, street, landmark, city, pincode) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);
basePath: service.address
jsonMaps:
- jsonPath: $.service.address.id
- jsonPath: $.service.address.tenantId
- jsonPath: $.service.id
- jsonPath: $.service.address.doorNo
- jsonPath: $.service.address.plotNo
- jsonPath: $.service.address.buildingName
- jsonPath: $.service.address.street
- jsonPath: $.service.address.landmark
- jsonPath: $.service.address.city
- jsonPath: $.service.address.pincode
The above configuration is used to insert data published on the kafka topic save-pgr-request
in the tables eg_pgr_service_v2
and eg_pgr_address_v2
. Similarly configuration can be written to update data. Following is a sample configuration:
- version: 1.0
description: Updates pgr service request in tables
fromTopic: update-pgr-request
isTransaction: true
queryMaps:
- query: UPDATE eg_pgr_service_v2 SET servicecode=?,additionaldetails=?, lastmodifiedby=?, lastmodifiedtime=? WHERE id=?;
basePath: service
jsonMaps:
- jsonPath: $.service.serviceCode
- jsonPath: $.service.additionalDetail
type: JSON
dbType: JSONB
- jsonPath: $.service.auditDetails.lastModifiedBy
- jsonPath: $.service.auditDetails.lastModifiedTime
- jsonPath: $.service.id
- query: UPDATE eg_pgr_address_v2 SET doorno=?, plotno=?, buildingname=?, street=?, landmark=?, city=?, pincode=? WHERE id=?;
basePath: service.address
jsonMaps:
- jsonPath: $.service.address.doorNo
- jsonPath: $.service.address.plotNo
- jsonPath: $.service.address.buildingName
- jsonPath: $.service.address.street
- jsonPath: $.service.address.landmark
- jsonPath: $.service.address.city
- jsonPath: $.service.address.pincode
- jsonPath: $.service.address.id
The above configuration is used to update the data in tables. Similarly upsert operation can be done using ON CONFLICT() function in psql. Following is a list of table describing each field in the configuration.
Variable Name | Description |
---|---|
| The module name to which the configuration belongs |
| Version of the config |
| Detailed description about the operations performed by the config |
| Kafka topic from which data has to be persisted in DB |
| Flag to enable/disable perform operations in Transaction fashion |
| Prepared Statements to insert/update data in DB |
| JsonPath of the object that has to be inserted/updated. |
| JsonPath of the fields that has to be inserted in table columns |
| Type of field |
| DB Type of the column in which filed is to be inserted |