This example demonstrates how to run the Open-VE as master-slave architecture.
Note: In this example, the master node is hosted at localhost:8081
, and the slave node is hosted at localhost:8082
.
Open-VE supports a master-slave architecture designed for scalability and compatibility with microservice environments.
In slave mode, Open-VE connects to the master server and syncs validation rules every 30 seconds.
When a validation check request is made to the master server, it redirects the request across the connected slave servers.
Additionally, you can directly request validation checks to the slave servers.
open-ve run --mode=master --http-port=8081 --grpc-port=9001
open-ve run --mode=slave --slave-id=slave-node-id --slave-master-http-addr=http://localhost:8081 --slave-slave-http-addr=http://localhost:8082 --http-port=8082 --grpc-port=9002
curl --request POST \
--url http://localhost:8081/v1/dsl \
--header 'Content-Type: application/json' \
--data '{
"validations": [
{
"id": "user",
"cels": [
"size(name) < 20"
],
"variables": [
{
"name": "name",
"type": "string"
}
]
}
]
}'
curl --request POST \
--url http://localhost:8082/v1/dsl \
--header 'Content-Type: application/json' \
--data '{
"validations": [
{
"id": "item",
"cels": [
"price > 0",
"size(image) < 360"
],
"variables": [
{
"name": "price",
"type": "int"
},
{
"name": "image",
"type": "bytes"
}
]
}
]
}'
curl --request GET \
--url http://localhost:8081/v1/dsl \
--header 'Content-Type: application/json'
{
"validations": [
{
"id": "user",
"cels": ["size(name) < 20"],
"variables": [
{
"name": "name",
"type": "string"
}
]
}
]
}
curl --request GET \
--url http://localhost:8082/v1/dsl \
--header 'Content-Type: application/json'
{
"validations": [
{
"id": "item",
"cels": ["price > 0", "size(image) < 360"],
"variables": [
{
"name": "price",
"type": "int"
},
{
"name": "image",
"type": "bytes"
}
]
}
]
}
Although only part of the validation rules are registered with the master node, you can request validation for all rules, including those on the slave nodes.
curl --request POST \
--url http://localhost:8081/v1/check \
--header 'Content-Type: application/json' \
--data '{
"validations": [
{
"id": "item",
"variables": {
"price": -100,
"image": "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAADElEQVR4nGO4unY2AAR4Ah51j5XwAAAAAElFTkSuQmCC"
}
},
{
"id": "user",
"variables": {
"name": "longlonglonglongname"
}
}
]
}'
{
"results": [
{
"id": "user",
"isValid": false,
"message": "failed validations: size(name) < 20"
},
{
"id": "item",
"isValid": false,
"message": "failed validations: price > 0"
}
]
}