Bỏ qua đến nội dung chính

Dispatchers

Dispatchers propagate incremental policy updates to multiple enforcer instances (e.g. a cluster). They use a consistency protocol (e.g. Raft) so all enforcers eventually see the same policy. Casbin’s normal API (AddPolicy, RemovePolicy, etc.) is unchanged; the dispatcher sends updates to other nodes.

Two parts: (1) hooks inside Casbin that the dispatcher implements, and (2) dispatcher-specific setup (e.g. cluster membership, config).

ghi chú

Dispatchers only sync changes after init. They do not fix existing divergence. Start all enforcers with the same policy (e.g. from the same DB or snapshot) before enabling a dispatcher.

Available dispatchers:

Adapter Type Author Description
Hashicorp Raft Dispatcher Raft Casbin A dispatcher based on Hashicorp Raft
KDKYG/casbin-dispatcher Raft @KDKYG A dispatcher based on Hashicorp Raft

DistributedEnforcer

DistributedEnforcer wraps SyncedEnforcer to work with dispatchers.

    e, _ := casbin.NewDistributedEnforcer("examples/basic_model.conf", "examples/basic_policy.csv")