How to push (produce ) messages into the Kafka broker using java?

                                   How to push (produce ) messages into the Kafka broker using java


  • First, create the properties class object for loading the Kafka producer properties.
  • After Connection creation of Kafka producer use the send method to push the message into the broker.
  • Finally, Close the Kafka producer connection.
Producing message into broker
import java.util.Properties; import org.apache.kafka.clients.producer.KafkaProducer; import org.apache.kafka.clients.producer.ProducerRecord; /** * * @author:Janardhan Randhi * @Date:Oct 23, 2018 * @Class: This class push the messages into kafka broker. */ public class Producer { public static void main(String[] args) { Properties properties = new Properties(); properties.put("bootstrap.servers", "localhost:9092"); properties.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer"); properties.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer"); KafkaProducer kafkaProducer = new KafkaProducer(properties); try { for (int i = 0; i < 100; i++) { System.out.println(i); kafkaProducer.send(new ProducerRecord("janardhan", Integer.toString(i), "test message - " + i)); } } catch (Exception e) { e.printStackTrace(); } finally { kafkaProducer.close(); } } }

SUBSCRIBE TO OUR NEWSLETTER

I’m the Founder of quickdevops.com. I am a Professional Blogger, Application developer, YouTuber. I’ve been blogging since 2015.I spend a lot of time learning new techniques and actively help other people learn web development through a variety of help groups and writing web development tutorials for my website and blog about advancements in web design and development.Besides programming I love spending time with friends and family and can often be found together going out catching the latest movie or planning a trip to someplace I've never been before.

52 Responses to "How to push (produce ) messages into the Kafka broker using java?"

  1. I really like your article. It’s evident that you have a lot knowledge on this topic. Your points are well made and relatable. Thanks for writing engaging and interesting material. apple phone mockup

    ReplyDelete
  2. I completely understand everything you have said. Actually, I browsed through your additional content articles and I think you happen to be absolutely right. Great job with this online site. iphone psd

    ReplyDelete
  3. Just saying thanks wouldn’t just be enough, for the fantastic fluency in your writing.
    additional reading

    ReplyDelete
  4. Hey! Good stuff, please keep us posted when you post something like that! device mockup

    ReplyDelete
  5. As soon as I found this internet site I went on reddit to share some of the love with them. اردو شاعری Naveed Ahmed

    ReplyDelete
  6. I gotta favorite this web site it seems very useful very beneficial 예스 카지노

    ---------------------------

    Hi my friend! I want to say that this article is amazing, nice written and include almost all important infos. I would like to see more posts like this . 더킹 카지노

    ReplyDelete
  7. I think other site proprietors should take this web site as an model, very clean and great user friendly style and design, let alone the content. You’re an expert in this topic! 안전놀이터

    --------------------------------------------------------------------------------------------------------------------------------


    I believe that is among the most significant information for me. And i’m satisfied studying your article. But wanna observation on some normal things, The web site style is perfect, the articles is in point of fact excellent . Excellent task, cheers. 스포츠중계

    ReplyDelete
  8. Hi I am so delighted I found your blog page, I really found you by accident, while I was browsing on Yahoo for something else, Anyways I am here now and would just like to say cheers for a incredible post and a all round interesting blog (I also love the theme/design), I don’t have time to look over it all at the minute but I have saved it and also added in your RSS feeds, so when I have time I will be back to read more, Please do keep up the excellent job. https://royalcbd.com/product/cbd-oil-2500mg/

    ReplyDelete
  9. I appreciate your work , thanks for all the informative blog posts. 먹튀검증

    ReplyDelete
  10. Thank you, I’ve recently been searching for info about this subject for ages and yours is the best I’ve found so far. mlb중계


    -------------------------------------------------------

    thanx for such a fantastic website. Where else could someone get that kind of info written in such a perfect way? I have a presentation that I am presently working on, and I have been on the look out for such information. 해외스포츠중계

    ReplyDelete
  11. First, let’s kill off a genuine fabrication: You can not use a reverse cellular phone number lookup for totally free anywhere, anytime. top development companies

    ReplyDelete
  12. They are the public safety and security agency for the brokerage industry and they specialize in helping brokers adhere to all applicable rules and regulations as well as educating brokers on the laws. For more information about rules and regulation of mortgage loan, Maine FHA loan.

    ReplyDelete
  13. I really enjoy reading webdesign studios and also appreciate your work.

    ReplyDelete
  14. While its outside is certainly eye catching, the inside of the vessel is arguably just as impressive if recently released renderings for the design are anything to go by.
    https://www.betting33.com

    ReplyDelete
  15. Described as the "superstar area of the yacht," Escalade's huge saloon, which holds a mirrored ceiling, is split into two sections, with a kitchen on one side, and a lavish lounge area and a raised dining area on the other.
    https://www.syy577.com

    ReplyDelete
  16. In addition, the yacht has four en suite cabins, a large cinema screen, various sunbathing areas, an onboard garage with room for a tender boat and two jet skis, and a glass bottomed hot tub.
    https://www.dok222.com

    ReplyDelete
  17. While the Escalade concept hasn't been picked up by a shipyard as yet, Akalın, who has been working with Anwigema on the project since 2019, says they've received plenty of interest from potential buyers and he's confident it will be hitting the waters in the not too distant future.
    https://www.ccclub700.com

    ReplyDelete
  18. "She is the design that meets the needs of the modern world," he adds, explaining the project would take between six to 10 months to complete "with the right planning" once funding is secured.
    https://www.hgame75.com

    ReplyDelete
  19. laptops batteries

    HP Compaq Presario g62 Battery https://www.all-laptopbattery.com/hp-compaq-presario-g62.html
    HP Elitebook 8760w Battery https://www.all-laptopbattery.com/hp-elitebook-8760w.html
    HP Mini 3100 Battery https://www.all-laptopbattery.com/hp-mini-3100.html
    Akku Acer Aspire 7741z http://www.laptop-akkus.com/acer-aspire-7741z.html
    Akku Acer Aspire v3-771 http://www.laptop-akkus.com/acer-aspire-v3-771.html
    Akku Acer Gateway nv74 http://www.laptop-akkus.com/acer-gateway-nv74.html

    ReplyDelete
  20. I'm also visiting this site regularly, this web site is really nice and the users are genuinely sharing good thoughts.design firm la

    ReplyDelete
  21. https://www.all-laptopbattery.com/asus-g73s.html ASUS G73S Battery
    https://www.all-laptopbattery.com/ASUS-g71v.html ASUS G71V Battery
    https://www.all-laptopbattery.com/asus-a32-k55.html ASUS A32-K55 Battery
    http://www.laptop-akkus.com/hp-envy-14-sleekbook.html HP ENVY 14
    http://www.laptop-akkus.com/hp-elitebook-8530p.html HP EliteBook 8530p
    http://www.laptop-akkus.com/hp-envy-dv7-7000.html HP Envy DV7-7000

    ReplyDelete
  22. https://www.dnfl150.com/gatsby
    https://www.dnfl150.com/33casino
    https://www.dnfl150.com/ondasino
    https://www.dnfl150.com

    ReplyDelete
  23. In spite of its recognized significance, the message is frequently the most disregarded and belittled part of a showcasing correspondences crusade. Once made, it's only sometimes examined. whats mod apks

    ReplyDelete
  24. When your website or blog goes live for the first time, it is exciting. That is until you realize no one but you and your. fx마진거래

    ReplyDelete
  25. Below you will understand what is important, the idea provides one of the links with an exciting site: fx마진거래

    ReplyDelete
  26. There is so much in this article that I would never have thought of on my own. Your content gives readers things to think about in an interesting way. Thank you for your clear information. receive SMS free

    ReplyDelete
  27. I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well. Thanks... clothing designer Slough

    ReplyDelete
  28. They refine those designs via daily updates and frequent communication product design companies.
    company logo design

    ReplyDelete
  29. Thank you for sharing this. It was helpful. Keep sharing such syuff.
    Also checkout Nulls Clash.

    ReplyDelete
  30. Yes I also wanted to ask this also. Thanks for sharing!

    ReplyDelete
  31. Great! We will be connecting to this enormous post on our site. Continue the good writing.
    mobile design agency

    ReplyDelete
  32. The life of a freight broker is anything but routine. Find out here what a freight broker is, what a freight broker does, how they do it, when they do it, with whom they do it and why they do it. LOCAL MORTGAGE SERVICES EDMONTON

    ReplyDelete
  33. Great post I have to say and thanks for the info. Education is definitely a complicated subject. However, it remains one of the main themes of our time. I appreciate your post and I look forward to more.

    ReplyDelete
  34. I really like and appreciate your blog post. Much thanks again. Want more.
    privnote

    ReplyDelete
  35. Excellent! Thanks for sharing such a great information.. It really helpful to me. Are you interested in free packs Tokens, Packs, and other exclusive in-game items and freebies? if yes then I share one blog about 2k locker Code, read it once.

    ReplyDelete
  36. Public Relationship of Real estate professionals (NAR) conjecture: 6% in 2016. toprankinmortgages

    ReplyDelete
  37. Property mortgage is a popular way to finance the purchase of a home or other real estate. toprankinmortgages.com

    ReplyDelete
  38. Desirable It looks like you've put a lot of work into this.

    ReplyDelete
  39. They ensure borrowers are aware of potential prepayment penalties. http://www.toprankinmortgages.com

    ReplyDelete