Persister Configuration

Overview

Persister Service persists data in the database in a sync manner providing very low latency. The queries which have to be used to insert/update data in the database are written in yaml file. The values which have to be inserted are extracted from the json using jsonPaths defined in the same yaml configuration.

Sample Configuration

Below is a sample configuration which inserts data in a 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, the 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, the upsert operation can be done using ON CONFLICT() function in psql.

Variable List

The table below describes each field variable in the configuration.

Last updated

All content on this page by eGov Foundation is licensed under a Creative Commons Attribution 4.0 International License.