消息发布api
pom.xml
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-clients</artifactId>
<version>0.11.0.0</version>
</dependency>
producer.properties
生产数据的配置信息,放在resources下面
# Kafka服务端的主机名和端口号
bootstrap.servers=mini1:9092,mini2:9092,mini3:9092
# specify the compression codec for all data generated: none, gzip, snappy, lz4
compression.type=none
# 等待所有副本节点的应答 (follower角色的分区从leader角色的分区中同步完毕消息后,给leader反馈信息)
acks=all
#消息发送最大尝试次数
retries=1
#一批消息处理大小
batch.size=16384
# name of the partitioner class for partitioning events; default partition spreads data randomly
partitioner.class=Partition.Mypartition
# the maximum amount of time the client will wait for the response of a request
#request.timeout.ms=
# how long `KafkaProducer.send` and `KafkaProducer.partitionsFor` will block for
#max.block.ms=
# the producer will wait for up to the given delay to allow other records to be sent so that the sends can be batched together
# 请求延时
linger.ms=1
# the maximum size of a request in bytes
#max.request.size=
# the default batch size in bytes when batching multiple records sent to a partition
#batch.size=
# the total bytes of memory the producer can use to buffer records waiting to be sent to the server
#发送缓存区内存大小
buffer.memory=33554432
#消息的key对应的序列化类
key.serializer=org.apache.kafka.common.serialization.IntegerSerializer
#消息的value对应的序列化类
value.serializer=org.apache.kafka.common.serialization.StringSerializer
consumer.properties
# list of brokers used for bootstrapping knowledge about the rest of the cluster
# format: host1:port1