-
Notifications
You must be signed in to change notification settings - Fork 59
Load Local Configuration
With this sample, you will learn:
- Storage and format of local business configuration
- Business configuration SPI mechanism, you can customize the loading method of business configuration based on SPI
- An Integrated Developer Environment (IDE). Popular choices include IntelliJ IDEA, Spring Tools, Visual Studio Code, or Eclipse, and many more.
- A Java™ Development Kit (JDK). We recommend BellSoft Liberica JDK version 8 or version 11.
- Completed Register Business Configuration reading
<dependency>
<groupId>org.hiforce.lattice</groupId>
<artifactId>lattice-model</artifactId>
<version>1.0.11.2</version>
</dependency>
<dependency>
<groupId>org.hiforce.lattice</groupId>
<artifactId>lattice-runtime</artifactId>
<version>1.0.11.2</version>
</dependency>
<dependency>
<groupId>org.hiforce.lattice</groupId>
<artifactId>lattice-load-config-res</artifactId>
<version>1.0.11.2</version>
</dependency>
In the Register Business Configuration chapter, we programmatically defined the business configuration process. Without a program, we can also use JSON files to define business configuration, such as the business configuration in the previous example, which is defined in JSON as follows:
{
"bizCode": "business.b",
"priority": 1000,
"products": [
{
"code": "lattice.productGroupBuyProduct"
}
],
"extensions": [
{
"extCode": "OrderLinePriceExt.EXT_ORDER_LINE_CUSTOM_UNIT_PRICE",
"priorities": [
{
"code": "lattice.productGroupBuyProduct",
"type": "PRODUCT"
},
{
"code": "business.b",
"type": "BUSINESS"
}
]
}
]
}
This JSON text simply serializes the BusinessConfig object into JSON text format. Copy this content into a file and put it in the resource/lattice directory. The file name is named in lattice-{business-code}.json format.
This example is very simple. Start Lattice directly, without using code to declare the business configuration, and directly simulate a business invocation process. code show as below:
public class AutoLoadBusinessConfigSample {
public static void main(String[] args) {
Lattice.getInstance().start();
System.out.println("---------------------------------------");
LatticeOverlayProductSample.doBusiness("groupBy");
System.out.println("---------------------------------------");
}
}
The results are as follows:
---------------------------------------
GroupBuyProduct effect status:true
[Business B] overlay product unit price: 700
---------------------------------------
In this example, we import the lattice-load-config-res toolkit. The local business configuration loader in this toolkit implements the BusinessConfigLoadSpi interface as follows:
@AutoService(BusinessConfigLoadSpi.class)
public class BizConfigResourceLoader implements BusinessConfigLoadSpi {
......
}
In the same way, we can also write a configuration reader to implement the BusinessConfigLoadSpi interface, so that the business configuration can be read and loaded from the remote configuration library when the container is started, such as using Alibaba Cloud OSS, ACM, etc. This can be left to you as a small homework.
The sample code can be obtained by visiting: https://github.com/hiforce/lattice-sample/tree/main/lattice-load-business-config
Thanks..
Getting Started
Key Features
- Business Overlay Product
- Register Business Configuration
- Load Local Configuration
- Reduce Strategy
- UseCase Precipitation and Reuse
- RPC Invoke Extension
- Dynamic Loading
Key Concepts
Stories