https://github.com/jcasbin/kafka-watcher
Kafka Watcher is a kafka watcher for jCasbin.
https://github.com/jcasbin/kafka-watcher
abac acl auth authorization authz casbin java jcasbin kafka rbac watcher
Last synced: 6 months ago
JSON representation
Kafka Watcher is a kafka watcher for jCasbin.
- Host: GitHub
- URL: https://github.com/jcasbin/kafka-watcher
- Owner: jcasbin
- License: apache-2.0
- Created: 2021-06-10T11:58:13.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2023-11-05T14:47:35.000Z (over 1 year ago)
- Last Synced: 2023-11-05T15:36:17.999Z (over 1 year ago)
- Topics: abac, acl, auth, authorization, authz, casbin, java, jcasbin, kafka, rbac, watcher
- Language: Java
- Homepage: https://github.com/casbin/jcasbin
- Size: 10.7 KB
- Stars: 1
- Watchers: 3
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Kafka Watcher
---
[](https://github.com/jcasbin/kafka-watcher/actions/workflows/ci.yml)
[](https://central.sonatype.com/artifact/org.casbin/kafka-watcher)
KafkaWatcher is a [Kafka](https://kafka.apache.org) watcher for [jCasbin](https://github.com/casbin/jcasbin).
## Installation
For Maven
``` xml
org.casbin
kafka-watcher
1.1.0```
## Simple Example
```java
public static void main(String[] args) {
// Initialize the watcher.
// Use the Kafka properties and topic name as parameter.
Map producerProps = new HashMap<>();
producerProps.put("bootstrap.servers", "127.0.0.1:9092");
producerProps.put("acks", "all");
producerProps.put("retries", 0);
producerProps.put("batch.size", 16384);
producerProps.put("linger.ms", 1);
producerProps.put("buffer.memory", 33554432);
producerProps.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
producerProps.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");Map consumerProps = new HashMap<>();
consumerProps.put("bootstrap.servers", "127.0.0.1:9092");
consumerProps.put("group.id", "my-consumer-group-01");
consumerProps.put("enable.auto.commit", "true");
consumerProps.put("auto.commit.interval.ms", "1000");
consumerProps.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
consumerProps.put("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
String topic="jcasbin-topic";
KafkaWatcher kafkaWatcher = new KafkaWatcher(producerProps,consumerProps, topic);// Initialize the enforcer.
Enforcer enforcer = new Enforcer("examples/rbac_model.conf", "examples/rbac_policy.csv");// Set the watcher for the enforcer.
enforcer.setWatcher(redisWatcher);// Set callback to local example
Runnable updateCallback = ()->{
//do something
};
kafkaWatcher.setUpdateCallback(updateCallback);// Update the policy to test the effect.
enforcer.savePolicy();
}
```## Getting Help
- [jCasbin](https://github.com/casbin/jCasbin)
- [kafka-client](https://github.com/apache/kafka)## License
This project is under Apache 2.0 License. See the [LICENSE](LICENSE) file for the full license text.