State

The State Adapter is responsible for persistence in database, cache, 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 follow a summary of the main configuration parameters.

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

The State Adapter supports multiple data persistences

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

In this type of implementation, each service must have 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 customizing caching services

DB

The Devprime platform provides several parameters for customizing the State.

Storage

Azure Storage, AWS Storage , Google Cloud Storage

Last modified August 20, 2024 (2f9802da)