Expand description
SPI (Service Provider Interface) module
SPI (服务提供接口) 模块
The SPI in BIOS is used to provide different scenario-oriented capabilities. These capabilities are abstracted into standardized service interfaces for other modules to call. Based on these standardized service interfaces, different backend implementations can be extended and interfaced.
BIOS中的SPI用于提供面向不同场景的能力。这些能力抽象成标准化的服务接口,供其他模块调用。基于这些标准化的服务接口,可扩展对接不同的后端实现。
§Example of invoke flow: full-text search service / 调用流程举例:全文搜索服务:
+------------------+
+-----------+ +----------+ +-+backend-postgresql|
| spi-basic | |spi-search+----+ +------------------+--+
+-----+-----+ +----+-----+ +-+backend-elasticsearch|
1. Init domain | | +---------------------+
| | 2. Init special entity
| |
| | 3. Init special API
4. Init common API | |
| |
+----------+ | |
---->|Common API+---> | |
+----------+ | |
5. Add backend service | |
(POST /ci/manage/bs) | |
| | +-----------+
6. Add cert to tenant/app | | <---+Special API|<----
(PUT /:id/rel/:app_tenant_id) | | +-----------+
| | 7. Request some apis
| |
8. Init and return backend client | |
(spi_funs) | |
| | 9. Call client to execute request
| |
| | 10. Response data
| | §Key design:
- Reuse RBUM’s ability
- Each SPI service has a
rbum_domainfor initializing domain objects. For example, therbum_domain=spi-searchof spi-search - Each SPI service has one or more backend implementations,
each corresponding to a
rbum_kind. Different SPI services can share the samerbum_kind. For example, therbum_kind=spi-bs-pgandrbum_kind=spi-bs-esof spi-search - Each SPI backend implementation can have multiple connections, corresponding to
rbum_item and extended spi_bs. For example, multiple connections can be specified forspi-bs-pgof spi-search - The connection information of each SPI backend implementation is stored in
rbum_cert - The binding relationship between each SPI backend implementation and the corresponding tenant or application must be bound before use,
and the binding relationship is stored in
rbum_rel, with the tag asspi_ident
- Each SPI service has a
- No request authentication is done.
The SPI service trusts the authentication information carried by the request (
akinTardisContext, corresponding to the Id of the tenant or application). The authentication logic will be implemented uniformly by the gateway - Delayed initialization.
The backend implementation of each SPI service is initialized (client generated) only when called for the first time to reduce resource consumption at startup.
See
crate::spi::spi_funs::SpiBsInstfor details
§关键设计:
- 复用RBUM的能力
- 每个SPI服务都有一个
rbum_domain,用于初始化领域对象。 如:spi-search的rbum_domain=spi-search - 每个SPI服务有一个或多个后端实现,每个后端实现对应一个
rbum_kind。不同的SPI服务可以共用相同的rbum_kind。如:spi-search的rbum_kind=spi-bs-pg和rbum_kind=spi-bs-es - 每个SPI的后端实现可以有多个,对应于
rbum_item及扩展的spi_bs。如可以为spi-search的spi-bs-pg指定多个连接 - 每个SPI后端实现的连接信息存储于
rbum_cert - 每个SPI后端实现的要绑定给对应的租户或应用后才能使用,绑定关系存储于
rbum_rel,tag为spi_ident
- 每个SPI服务都有一个
- 不做请求认证。SPI服务信任请求带来的认证信息(
TardisContext中的ak,对应于租户或应用的Id)。认证的逻辑将由网关统一实现 - 延时初始化。SPI服务的每个后端实现只有在第一次调用时才会初始化(生成client),以减少启动时的资源消耗。详见
crate::spi::spi_funs::SpiBsInst
Modules§
- api
- dto
- macros
- SPI macros
- serv
- spi_
constants - spi_
funs - SPI backend service instance initialization and extraction SPI后端服务实例初始化和提取
- spi_
initializer - SPI initializer