The project I took it from is Camus which is Kafka->Hadoop ETL project, and I just made some slight changes related to newer Zookeeper, as well as some changes configuration-wise.
My embedded Kafka & Zookeeper servers are available at this gist. All the code is tested against Kafka 0.8.1.1 and Zookeeper 3.4.6.
Here is simple example on how to setup Zookeeper at fixed port (2181), and 2 Kafka servers at random available ports:
EmbeddedZookeeper embeddedZookeeper = new EmbeddedZookeeper(2181);
List<Integer> kafkaPorts = new ArrayList<Integer>();
// -1 for any available port
kafkaPorts.add(-1);
kafkaPorts.add(-1);
EmbeddedKafkaCluster embeddedKafkaCluster = new EmbeddedKafkaCluster(embeddedZookeeper.getConnection(), new Properties(), kafkaPorts);
embeddedZookeeper.startup();
System.out.println("### Embedded Zookeeper connection: " + embeddedZookeeper.getConnection());
embeddedKafkaCluster.startup();
System.out.println("### Embedded Kafka cluster broker list: " + embeddedKafkaCluster.getBrokerList());
Thread.sleep(10000);
embeddedKafkaCluster.shutdown();
embeddedZookeeper.shutdown();
I'm using your example to test reading from Kafka into a Storm topology. How would you setup a topic and populate it with some messages?
ReplyDeleteThanks
Well, you just use standard client APIs to produce a messages (producer API), same as you would do if there was remote broker in play here. Same thing for creating a topic.
ReplyDeleteAlthough creating a topic is something mostly done via CLI command, but here you need to use programmatic way, thus look at Kafka's AdminClient class.
Something like:
ZkClient zkClient = new ZkClient(embeddedZookeeper.getConnection());
AdminUtils.createTopic(zkClient, topic, 1, 1, new Properties());
Any advice on how you coordinate producing messages and then consuming them as part of a test? Particularly where the test logic isn't in the consumer but the test calls the producer and consumer to generate and fetch the data to validate. It is simplest to produce and consume concurrently, but that could be a bit tricky to coordinate. Not sure if one can coordinate it to producing test messages first then consuming after the production serially/sequentially to simplify testing. Your thoughts?
ReplyDeleteIf I understood your needs, you need some kind of "promise" mechanism for fetching the result of async process (in this case consumer callback) in the original thread that produced the message. There are other ways, but if you're using java 8, the most obvious way is CompletableFuture. You just call future.compete(message) from your consumer code, and have producer waiting for it in original thread via future.get();
ReplyDeleteHi,
ReplyDeleteI just tried the code under 0.8.2 kafka version. I have an issue when I try to push something in the only one Kafka broker.
[KafkaApi-1] error when handling request Name: TopicMetadataRequest; Version: 0; CorrelationId: 321764; ClientId: producer-1; Topics: offers
kafka.admin.AdminOperationException: replication factor: 1 larger than available brokers: 0
From my understanding, it seems that no Kafka server is started ?
I solved it by using
ReplyDeleteZkClient zkClient = new ZkClient(embeddedZookeeper.getConnection(), 10000, 10000, ZKStringSerializer$.MODULE$);
AdminUtils.createTopic(zkClient, topic, 10, 1, new Properties());
This is the exact information I am been searching for, Thanks for sharing the required infos with the clear update and required points.
ReplyDeleteredmi service center in velachery
redmi note service center in chennai
redmi mobile service centre in chennai
Really nice and interesting post. I was looking for this kind of information and enjoyed reading this one. Keep posting. Thanks for sharing.
ReplyDeletedate analytics certification training courses
data science courses training
wow, great, I was wondering how to cure acne naturally. and found your site by google, learned a lot, now i’m a bit clear. I’ve bookmark your site and also add rss. keep us updated.
ReplyDeleteData Science Course in Pune
Wow, what an awesome spot to spend hours and hours! It's beautiful and I'm also surprised that you had it all to yourselves! Kindly visit us @ Best HIV Treatment in India | Top HIV Hospital in India | HIV AIDS Treatment in Mumbai
ReplyDeleteHIV Specialist in Bangalore | HIV Positive Treatment in India | Medicine for AIDS in India
Nice blog, it's so knowledgeable, informative, and good looking site. I appreciate your hard work. Good job. Thank you for this wonderful sharing with us. Keep Sharing.
ReplyDeleteKindly visit us @ 100% Job Placement | Best Colleges for Computer Engineering
Biomedical Engineering Colleges in Coimbatore | Best Biotechnology Colleges in Tamilnadu
Biotechnology Colleges in Coimbatore | Biotechnology Courses in Coimbatore
Best MCA Colleges in Tamilnadu | Best MBA Colleges in Coimbatore
Engineering Courses in Tamilnadu | Engg Colleges in Coimbatore
I have to search sites with relevant information on given topic and provide them to teacher our opinion and the article.
ReplyDeleteThank you for your post, I look for such article along time, today i find it finally. this post give me lots of advise it is very useful for me.
It should be noted that whilst ordering papers for sale at paper writing service, you can get unkind attitude. In case you feel that the bureau is trying to cheat you, don't buy term paper from it.
Data Science Courses
Its as if you had a great grasp on the subject matter, but you forgot to include your readers. Perhaps you should think about this from more than one angle.digital marketing course in singapore
ReplyDelete
ReplyDeleteA very inspiring blog your article is so convincing that I never stop myself to say something about it.
Nice blog...
ReplyDeleteBest Travels in Madurai | Tours and Travels in Madurai | Best tour operators in Madurai
This is a wonderful article. I really enjoyed reading this article. Thanks for sharing such detailed information.
ReplyDeleteData Science Course
Data Science Course in Marathahalli
Data Science Course Training in Bangalore
The Blog is Creative.
ReplyDeleteData Science Training Course In Chennai | Data Science Training Course In Anna Nagar | Data Science Training Course In OMR | Data Science Training Course In Porur | Data Science Training Course In Tambaram | Data Science Training Course In Velachery
ReplyDeleteHi, Very nice article. I hope you will publish again such type of post. Thank you!
Corporate gifts ideas | Corporate gifts
Corporate gifts singapore | Corporate gifts in singapore
Promotional gifts singapore | Corporate gifts wholesale Singapore
leather corporate gifts singapore | t shirts supplier singapore
thumb drive supplier singapore | business card holder singapore
corporate gifts supplier | customized corporate gifts singapore
corporate gifts supplier singapore
It's very nice blog. i like that your article.
ReplyDeletePython Training in Chennai
Python Training in Bangalore
Python Training in Hyderabad
Python Training in Coimbatore
Python Training
python online training
python flask training
python flask online training
By reading this article, many things have piled up in my mind which made me to think about it. You have put some high quality and valuable information here that any reader would love to read. I sincerely share many of your views in this article. Data Science Training In Chennai | Certification | Data Science Courses in Chennai | Data Science Training In Bangalore | Certification | Data Science Courses in Bangalore | Data Science Training In Hyderabad | Certification | Data Science Courses in hyderabad | Data Science Training In Coimbatore | Certification | Data Science Courses in Coimbatore | Data Science Training | Certification | Data Science Online Training Course
ReplyDeleteIt’s very informative and you are obviously very knowledgeable in this area. You have opened my eyes to varying views on this topic with interesting and solid content.
ReplyDeletedata analytics courses
Actually I read it yesterday but I had some thoughts about it and today I wanted to read it again because it is very well written.
ReplyDeleteData Analyst Course
Wonderful post,This article have helped greatly continue writing...
ReplyDeleteHIV/AIDS Complete cure test result in Tamilnadu | Hiv aids treatment in bangalore
Best hiv doctor in india | Hiv positive treatment in india
Medicine for aids in india
This is my first time i visit here. I found so many entertaining stuff in your blog, especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the leisure here! Keep up the good work. I have been meaning to write something like this on my website and you have given me an idea.
ReplyDeletedata science courses
Nice blog, it's so knowledgeable, informative, and good looking site. I appreciate your hard work. Good job. Thank you for this wonderful sharing with us. Keep Sharing.
ReplyDeleteDevOps Training in Chennai
DevOps Course in Chennai
Thank a lot. You have done excellent job. I enjoyed your blog . Nice efforts
ReplyDeletedata science course
Thanks for sharing this blog its very helpful to implement in our work
ReplyDeleteLearn Japanese Language | Learn Japanese Online
Here at this site is really a fastidious material collection so that everybody can enjoy a lot.
ReplyDeletebusiness analytics course in hyderabad
I would like to thank you for the efforts you have made in writing this article. I am hoping for the same best work from you in the future as well. In fact your creative writing abilities have inspired me to start my own Blog Engine blog now. Really the blogging is spreading its wings rapidly. Your write up is a fine example of it.
ReplyDeletebest data science training in hyderabad