观察者
我们支持使用分布式消息系统,例如 etcd 来保持多个Casbin执行器实例之间的一致性。 因此,我们的用户可以同时使用多个Casbin 执行器来处理大量的权限检查请求。
与策略存储 adapters类似,我们没有把watcher的代码放在主库中。 任何对新消息系统的支持都应该作为watcher程序来实现。 完整的Casbin watchers列表如下所示。 欢迎任何第三方对 watcher 进行新的贡献,如果有请告知我们,我将把它放在这个列表中:)
Go
** 监视器** | 类型 | 作者 | 说明 |
---|---|---|---|
Etcd Watcher | KV store | Casbin | etcd 的监视器 |
Redis Watcher | KV store | Casbin | Watcher for Redis |
Redis Watcher | KV store | @billcobbler | Watcher for Redis |
Kafka Watcher | Messaging system | @wgarunap | Watcher for Apache Kafka |
NATS Watcher | Messaging system | Soluto | Watcher for NATS |
ZooKeeper Watcher | Messaging system | Grepsr | Watcher for Apache ZooKeeper |
NATS, RabbitMQ, GCP Pub/Sub, AWS SNS & SQS, Kafka, InMemory | Messaging System | @rusenask | Watcher based on Go Cloud Dev Kit that works with leading cloud providers and self-hosted infrastructure |
RocketMQ Watcher | Messaging system | @fmyxyz | Watcher for Apache RocketMQ |
WatcherEx
In order to support incremental synchronization between multiple instances, we provide the WatcherEx interface. We hope it can notify other instances when the policy changes, but there is currently no implementation of WatcherEx. We recommend that you use dispatcher to achieve this.
Compared with Watcher interface, with implementing WatcherEx what kind of update action can be distinguished, etc AddPolicy, RemovePolicy, etc.
WatcherEx Apis:
api | description |
---|---|
SetUpdateCallback(func(string)) error | SetUpdateCallback sets the callback function that the watcher will call, when the policy in DB has been changed by other instances. A classic callback is Enforcer.LoadPolicy(). |
Update() error | Update calls the update callback of other instances to synchronize their policy. It is usually called after changing the policy in DB, like Enforcer.SavePolicy(), Enforcer.AddPolicy(), Enforcer.RemovePolicy(), etc. |
Close() | Close stops and releases the watcher, the callback function will not be called any more. |
UpdateForAddPolicy(params …string) error | UpdateForAddPolicy calls the update callback of other instances to synchronize their policy. It is called after Enforcer.AddPolicy() |
UpdateForRemoveFilteredPolicy(fieldIndex int, fieldValues …string) error | UpdateForRemoveFilteredPolicy calls the update callback of other instances to synchronize their policy. It is called after Enforcer.RemoveFilteredNamedGroupingPolicy() |
UpdateForSavePolicy(model model.Model) error | UpdateForSavePolicy calls the update callback of other instances to synchronize their policy. It is called after Enforcer.RemoveFilteredNamedGroupingPolicy() |
最后编辑: kuteng 文档更新时间: 2021-06-22 19:03 作者:kuteng