Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

A brief introduction to kakfa producers of java Code

2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains the "brief introduction of kakfa producers of java code". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "kakfa producer brief introduction of java code".

Kafka schematic diagram

Kafka producer of JAVA source code, this client uses kafka console command line, consumer, producer uses code coding. Read a lot of producer code with props.put ("zk.connect", "n2:2181/jafka"); really feel puzzled, without this parameter can run well, practice to know, understand the principle is really important, as follows:

Import java.util.Properties

Import kafka.javaapi.producer.Producer

Import kafka.producer.KeyedMessage

Import kafka.producer.ProducerConfig

/ * *

* 0.7.2

* @ author Administrator

*

, /

Public class ProducerSample {

Public static void main (String [] args) {

String topicName = "test"

String data = "this is a java-test. I Am gaojs"

ProducerSample ps = new ProducerSample ()

Properties props = new Properties ()

Props.put ("metadata.broker.list", "192.168.1.101 purl 9092")

Props.put ("serializer.class", "kafka.serializer.StringEncoder")

Props.put ("request.required.acks", "1")

ProducerConfig config = new ProducerConfig (props)

Producer producer = new Producer (config)

KeyedMessage keyedMessage = new KeyedMessage (topicName, data)

Producer.send (keyedMessage)

Producer.close ()

}

}

MAVEN environment

Org.apache.kafka

Kafka_2.10

0.9.0.1

Jmxtools

Com.sun.jdmk

Jmxri

Com.sun.jmx

Jms

Javax.jms

Log4j

Log4j

1.2.15

Jmxtools

Com.sun.jdmk

Jmxri

Com.sun.jmx

Jms

Javax.jms

Mail

Javax.mail

Junit

Junit

4.11

Test

Practice screenshot

Start zk

Thank you for your reading, the above is the content of "brief introduction of kakfa producers of java code". After the study of this article, I believe you have a deeper understanding of the brief introduction of kakfa producers of java code, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report