Skip to content

服务运行配置

runtime 配置块控制数据墙DBW 服务的全局行为。大多数字段有合理的默认值,不写 runtime 也能运行。但了解每个配置项有助于在生产环境中调优服务。

基本结构

json
{
  "runtime": {
    "rest": { "enabled": true, "path": "/api" },
    "graphql": { "enabled": true, "path": "/graphql" },
    "host": { "mode": "development" },
    "pagination": { "default-page-size": 100, "max-page-size": 100000 }
  }
}

REST 设置

字段说明默认值
rest.enabled全局启用/禁用 REST 端点true
rest.pathREST 端点路径前缀"/api"
rest.request-body-strict请求体中出现多余字段时是否拒绝true

request-body-stricttrue 时,POST/PUT/PATCH 请求体中的字段如果在数据库表中不存在,引擎会返回 400 错误。设为 false 允许忽略多余字段。

注意: path 不支持子路径(如 /api/data),只能设置一级路径前缀。

GraphQL 设置

字段说明默认值
graphql.enabled全局启用/禁用 GraphQLtrue
graphql.pathGraphQL 端点路径"/graphql"
graphql.allow-introspection是否允许架构内省查询true
graphql.depth-limit查询最大嵌套深度null(不限制)
graphql.multiple-mutations.create.enabled是否允许多重创建变更false

生产环境建议关闭 allow-introspection 以避免暴露完整的 API 架构。depth-limit 防止恶意深层嵌套查询消耗服务资源。

注意: path 不支持子路径。

MCP 设置

json
{
  "runtime": {
    "mcp": {
      "enabled": true,
      "path": "/mcp",
      "description": "数据访问服务",
      "dml-tools": {
        "describe-entities": true,
        "create-record": true,
        "read-records": true,
        "update-record": true,
        "delete-record": true,
        "execute-entity": true,
        "aggregate-records": { "enabled": true, "query-timeout": 30 }
      }
    }
  }
}
字段说明默认值
mcp.enabled全局启用 MCP 服务true
mcp.pathMCP 端点路径"/mcp"
mcp.description发送给 MCP 客户端的服务器描述null
mcp.dml-tools可设为布尔值(全部开/关)或对象(逐个控制)全部启用

aggregate-records 支持 query-timeout(1-600 秒)和 enabled 子属性。其他工具仅支持布尔值。

分页设置

字段说明默认值
pagination.default-page-size默认每页记录数100
pagination.max-page-size允许的最大每页记录数100000
pagination.next-link-relative分页链接使用相对 URLfalse

分页适用于 REST 的 $first 参数和 GraphQL 的 first 参数。客户端可以传 $first=-1 获取最大页大小。

next-link-relativetrue 时,分页 nextLink 使用相对 URL:

示例
false(默认)"nextLink": "https://localhost:5001/api/users?$after=..."
true"nextLink": "/api/users?$after=..."

主机设置

json
{
  "host": {
    "mode": "production",
    "max-response-size-mb": 158,
    "cors": { "origins": ["https://app.example.com"] },
    "authentication": {
      "provider": "Unauthenticated"
    }
  }
}
字段说明默认值
host.mode运行模式:developmentproductionproduction
host.max-response-size-mb单个响应允许的最大数据库结果大小(MB)158
host.cors.origins允许的跨域来源[]
host.cors.allow-credentials是否允许跨域携带凭据false
host.authentication.provider认证提供程序Unauthenticated

Development vs Production

行为DevelopmentProduction
Swagger UI启用禁用
详细错误信息启用禁用
健康检查匿名访问允许需配置 roles
日志级别DebugWarning

认证提供程序

提供程序用例说明
Unauthenticated默认,所有请求以 anonymous 身份运行无需额外配置
Custom第三方身份提供商(JWT)需配置 jwt.issuerjwt.audience
Simulator本地开发测试仅在 development 模式下有效

使用 Custom 认证时需配置 JWT:

json
{
  "authentication": {
    "provider": "Custom",
    "jwt": {
      "audience": "<api-audience>",
      "issuer": "https://<your-idp-domain>/"
    }
  }
}

注意: Simulator 提供程序仅在 host.modedevelopment 时有效。生产模式下配置 Simulator 会导致服务无法启动。

缓存设置

json
{
  "cache": {
    "enabled": true,
    "ttl-seconds": 30,
    "level-2": {
      "enabled": true,
      "provider": "redis",
      "connection-string": "@env('REDIS_CONN_STR')",
      "partition": "my-app"
    }
  }
}
字段说明默认值
cache.enabled全局缓存开关false
cache.ttl-seconds默认缓存生存时间(秒)5
cache.level-2.enabled启用分布式二级缓存false
cache.level-2.provider分布式缓存提供程序"redis"
cache.level-2.connection-string缓存服务连接字符串null
cache.level-2.partition隔离分布式缓存空间的分区名称null

cache.ttl-seconds 可在实体级被覆盖。启用全局缓存后,还需要在各实体上显式开启 cache.enabled

level-2.enabledtrue 时,配置了缓存级别 L1L2 的实体会先检查本地内存缓存,再检查分布式缓存,最后才访问数据库。

压缩设置

json
{
  "compression": {
    "level": "optimal"
  }
}
字段说明默认值
compression.levelHTTP 响应压缩级别"optimal"

支持的压缩级别:

描述压缩节省性能影响
optimal平衡比率和速度(默认)Gzip: ~90% / Brotli: ~92%中等 CPU 使用
fastest优先速度而非比率Gzip: ~90% / Brotli: ~91%低 CPU 使用
none无压缩0%

压缩由客户端的 Accept-Encoding 头触发,支持 Gzip 和 Brotli 算法。

遥测与日志

日志级别

json
{
  "telemetry": {
    "log-level": {
      "Azure.DataApiBuilder.Core": "information",
      "default": "warning"
    }
  }
}

按命名空间配置日志详细程度。log-level 是唯一支持在生产环境中热重载的配置项。

也可以通过启动参数指定全局日志级别:

bash
dab start --LogLevel Debug

日志级别选项:TraceDebugInformationWarningErrorCriticalNone。生产环境建议 WarningError

OpenTelemetry

json
{
  "telemetry": {
    "open-telemetry": {
      "enabled": true,
      "endpoint": "http://localhost:4317",
      "headers": "api-key=key",
      "service-name": "数据墙DBW",
      "exporter-protocol": "grpc"
    }
  }
}
字段说明默认值
open-telemetry.enabled启用 OpenTelemetrytrue
open-telemetry.endpointOpenTelemetry 收集器 URLnull
open-telemetry.headers导出头(逗号分隔){}
open-telemetry.service-name服务名称"数据墙DBW"
open-telemetry.exporter-protocol协议:grpchttpprotobuf"grpc"

gRPC(端口 4317)更快并支持流式传输,HTTP/protobuf(端口 4318)更简单且更容易调试。

文件日志

json
{
  "telemetry": {
    "file": {
      "enabled": true,
      "path": "/var/log/dab/dab-log.txt",
      "rolling-interval": "Day",
      "retained-file-count-limit": 7,
      "file-size-limit-bytes": 10485760
    }
  }
}
字段说明默认值
file.enabled启用文件日志false
file.path日志文件路径"/logs/dab-log.txt"
file.rolling-interval滚动间隔:MinuteHourDayMonthYearInfinite"Day"
file.retained-file-count-limit保留的日志文件最大数量1
file.file-size-limit-bytes滚动前的最大文件大小(字节)1048576

健康检查

json
{
  "health": {
    "enabled": true,
    "roles": ["admin", "support"],
    "cache-ttl-seconds": 5,
    "max-query-parallelism": 4
  }
}
字段说明默认值
health.enabled全局启用/禁用健康检查端点true
health.roles允许访问健康检查的角色(生产环境必需)null
health.cache-ttl-seconds健康检查报告缓存 TTL(秒)5
health.max-query-parallelism最大并发健康检查查询数(范围:1-8)4

开发环境与生产环境的行为

条件Development 行为Production 行为
health.enabled = false403403
roles 省略或 null显示健康状态403
当前角色不在 roles403403
当前角色在 roles显示健康状态显示健康状态
roles 包含 anonymous显示健康状态显示健康状态

使用 CLI 配置

bash
# 设置运行模式
dab configure --runtime.host.mode "development"

# 关闭 GraphQL
dab configure --runtime.graphql.enabled false

# 设置分页大小
dab configure --runtime.pagination.default-page-size 50

# 配置 MCP 路径
dab configure --runtime.mcp.path "/mcp"

# 启用压缩
dab configure --runtime.compression.level "optimal"

# 启用缓存
dab configure --runtime.cache.enabled true
dab configure --runtime.cache.ttl-seconds 30

CLI 会直接修改配置文件,与手动编辑 JSON 等效。

下一步

数据墙DBW 产品文档与开发指南。