State

The State Adapter is responsible for database persistence, caching, and storage on the Devprime platform. The Adapter State can be customized with a variety of options, including MongoDB, SQL Server, MySQL, PostgreSQL, ElasticSearch, Oracle, Redis, and other storage parameters such as Azure Store, AWS S3, Google Cloud Storage, and many others.

Configuring State with MongoDB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
  "DevPrime_State": [
    {
      "enable": "true",
      "alias": "State1",
      "type": "db",
      "dbtype": "mongodb",
      "connection": "mongodb://mongoadmin:LltF8Nx*yo@localhost:27017",
      "timeout": "5",
      "retry": "2",
      "dbname": "ms-order",
      "isssl": "true",
      "numberofattempts": "4",
      "durationofbreak": "45"
    }
  ],

In the table below, you can see a summary of the main configuration parameters.

State
enable Enable the State adapter (True/False)
alias Defines a unique name to identify the service
type Sets the State type (DB
dbtype Defines the database service (MongoDB
dbname Database Name / Collection
connection Defines the configuration of the access connection
timeout Sets the default timeout to fail
retry Configure the number of retries
isssl Enables a secure connection (True/False)
numberofattempts Sets the number of attempts
durationofbreak Set the duration of the Circuit-Break

The State Adapter supports multiple data persistences

The Devprime platform’s State Adapter supports more than one State service simultaneously, to cater to specific scenarios where it is necessary to have both MongoDB and Redis in the same microservice and one Storage.

In this type of implementation, it is necessary that each service has its own Alias.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
   "Devprime_State": [
    {
      "enable": "true",
      "alias": "State1",
      "type": "db",
      "dbtype": "mongodb",
      "connection": "mongodb://mongoadmin:LltF8Nx*yo@localhost:27017",
      "timeout": "5",
      "retry": "2",
      "dbname": "ms-order",
      "isssl": "true",
      "numberofattempts": "4",
      "durationofbreak": "45"
    },
    {
      "enable": "true",
      "alias": "State2",
      "dbtype": "redis",
      "connection": "127.0.0.x:6379",
      "timeout": "5",
      "retry": "2",
      "durationofbreak": "45"
    },
    {
      "enable": "true",
      "alias": "State3",
      "type": "storage",
      "storagetype": "file",        
      "timeout": "5",
      "retry": "2",
      "durationofbreak": "45"
    }
  ],

Example in the application log with this configuration:

1
2
3
[INF][State][Type "MongoDB"][Alias "State1"]["Database"]["Enable"]
[INF][State][Type "Redis"][Alias "State2"]["Database"]["Enable"]
[INF][State][Type "File"][Alias "State3"]["Storage"]["Enable"]

YAML example with application settings:
To export the configurations as an environment variable and use in Kubernetes, run the command in the Devprime CLI:
dp export kubernetes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
- name: devprime_state1
  value: "enable=true|||alias=State1|||type=db|||dbtype=mongodb|||
  connection=mongodb://mongoadmin:LltF8Nx*yo@mongodb.default.svc:27017|||
  timeout=5|||retry=2|||dbname=ms-order|||isssl=true|||numberofattempts=4|||
  durationofbreak=45" 
- name: devprime_state2
  value: "enable=true|||alias=State2|||dbtype=redis|||
  connection=127.0.0.x:6379|||timeout=5|||retry=2|||durationofbreak=45" 
- name: devprime_state3
  value: "enable=true|||alias=State3|||type=storage|||storagetype=file|||
  timeout=5|||retry=2|||durationofbreak=45"

Cache

The Devprime platform provides several parameters for the customization of caching services

DB

The Devprime platform provides several parameters for State customization.

Storage

Azure Storage, AWS Storage , Google Cloud Storage

Last modified January 10, 2024 (967dcac3)