Giter Club home page Giter Club logo

kafkasdk's Introduction

#KafkaSDK

##原理: 用户信息存储在zookeeper中,使用的是zookeeper的ACL权限控制来进用户行数据存储的加密。

###具体用法 1.新建一个kafkaUser类,这个kafkaUser构造函数是用户名,zookeeper的地址和用户密码 例如

KafkaUser user=new KafkaUser("xiaoming","localhost:2181","123");

2.新建一个HITKafkaClient类并提供默认,构造函数传入要操作的topic名称和要操作这个topic的用户,并用于获取生产者和消费者 当该用户无访问权限时

DefaultHITKafkaClient defalutHITKafkaClient=new DefaultHITKafkaClient("test2",user);
HITProducer hitProducer=defalutHITKafkaClient.getProducer();                                                     //获得生产者
hitProducer.HITsend("tttt");                                                                                                                            //发送消息    

打印结果:

[INFO ] 2016-04-23 19:33:53,834 method:hit.hitnslab.ConsumerSDK.HITConsumer.<init>(HITConsumer.java:32)
xiaoming has no right to use this topic 
Exception in thread "main" java.lang.NullPointerException
	at hit.hitnslab.ProducerSDK.HITProducer.HITsend(HITProducer.java:67)
	at example.test.main(test.java:40)

如果需要使某一用户可以使用该topic,则必须使用一个已经可以使用该topic的用户对他进行授权操作 例如

KafkaUser user1=new KafkaUser("zcc","localhost:2181","123");
List list=new ArrayList();
list.add(user);
user1.createPowerTopic("test2", list);

其中zcc是已有test2操作权限的用户,使用createPowerTopic(“topic名称”,授权的user组成的list)完成授权操作,完成授权后再次操作发送成功 打印结果

[DEBUG] 2016-04-23 19:43:22,229 method:kafka.utils.Logging$class.debug(Logging.scala:52)
Producer sending messages with correlation id 4 for topics [test2,0] to broker 2 on zcc-Inspiron-5521:9094
[DEBUG] 2016-04-23 19:43:22,230 method:kafka.utils.Logging$class.debug(Logging.scala:52)
Producer sent messages with correlation id 4 for topics [test2,0] to broker 2 on zcc-Inspiron-5521:9094

总体使用代码: 生产:

KafkaUser user=new KafkaUser("xiaoming","localhost:2181","123");
DefaultHITKafkaClient defalutHITKafkaClient=new DefaultHITKafkaClient("test2",user);    
HITProducer hitProducer=defalutHITKafkaClient.getProducer();        //获得生产者                                             
 hitProducer.HITsend("tttt");                                                                                                                            //发送消息    

消费两条数据:并将其加载到list中

  List<String> s=new ArrayList();
  s= hitConsumer.GetMessageAndFillWith(new String(),2);

kafkasdk's People

Contributors

hit-zcc avatar

Stargazers

DreamChaser avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.