1
第
章
kafka
应
⽤
实
战
之
ja
v
a
与
s
cala
操
作
案
例
、
参
数
设
置
说
明
前
置
说
明
参
数
设
置
、
ja
v
a
操
作
案
例
、
s
cala
操
作
案
例
鉴
于
kafka
在
实
际
使
⽤
时
,
绝
⼤多
数
应
⽤
场
景
均
为
Producer
和
Consumer
的
API
配
合
使
⽤
,
故
在
此
只
介
绍
这
两
种
API
操
作
⽅
法
,
其
它
的
Connector
和
Streams
可
以
视
⾃
身
情
况
⾃
⾏
学
习
。
Producer
常
⽤
参
数
1
、
参
数
设
置
说
明
前
置
说
明
参
数
设
置
○
参
数
名
称
NAME
描
述
DESCRIPTION
类
型
TYPE
默
认
值
DEFAU
LT
合
法
值
VALID
VALUES
重
要
性
IMPORTA
NCE
bootstra
p.servers
A
list
of
host/port
pairs
to
use
for
establishing
the
initial
connection
to
the
Kafka
cluster.
The
client
will
make
use
of
all
servers
irrespective
of
which
servers
are
specified
here
for
bootstrapping
—
this
list
only
impacts
the
initial
hosts
used
to
discover
the
full
set
of
servers.
This
list
should
be
in
the
form
list
high
2
host
1
:port
1
,host
2
:port
2
,....
Since
these
servers
are
just
used
for
the
initial
connection
to
discover
the
full
cluster
membership
(which
may
change
dynamically),
this
list
need
not
contain
the
full
set
of
servers
(you
may
want
more
than
one,
though,
in
case
a
server
is
down).
key.seria
lizer
Serializer
class
for
key
that
implements
the
Serializer
interface.
class
high
value.ser
ializer
Serializer
class
for
value
that
implements
the
Serializer
interface.
class
high
acks
The
number
of
acknowledgments
the
producer
requires
the
leader
to
have
received
before
considering
a
request
complete.
This
controls
the
durability
of
records
that
are
sent.
The
following
settings
are
common:
acks=
0
If
set
to
zero
then
the
producer
will
not
wait
for
any
acknowledgment
from
the
server
at
all.
The
record
will
be
immediately
added
to
the
socket
buffer
and
considered
sent.
No
guarantee
can
be
made
that
the
server
has
received
the
record
in
this
case,
and
the
retriesconfiguration
will
not
take
effect
(as
the
client
won't
generally
know
of
any
failures) The offset given
●
string
1
[all,
-
1
,
0
,
1
]
high
3
failures).
The
offset
given
back
for
each
record
will
always
be
set
to
-
1
.
acks=
1
This
will
mean
the
leader
will
write
the
record
to
its
local
log
but
will
respond
without
awaiting
full
acknowledgement
from
all
followers.
In
this
case
should
the
leader
fail
immediately
after
acknowledging
the
record
but
before
the
followers
have
replicated
it
then
the
record
will
be
lost.
acks=all
This
means
the
leader
will
wait
for
the
full
set
of
in-sync
replicas
to
acknowledge
the
record.
This
guarantees
that
the
record
will
not
be
lost
as
long
as
at
least
one
in-sync
replica
remains
alive.
This
is
the
strongest
available
guarantee.
●
●
buffer.m
emory
The
total
bytes
of
memory
the
producer
can
use
to
buffer
records
waiting
to
be
sent
to
the
server.
If
records
are
sent
faster
than
they
can
be
delivered
to
the
server
the
producer
will
block
for
max.block.msafter
which
it
will
throw
an
exception.
This
setting
should
correspond
roughly
to
the
total
memory
the
producer
will
use,
but
is
not
a
hard
bound
since
not
all
memory
the
producer
uses
is
used
for
buffering.
Some
additional
long
335544
32
[
0
,...]
high
4
memory
will
be
used
for
compression
(if
compression
is
enabled)
as
well
as
for
maintaining
in-flight
requests.
compres
sion.type
The
compression
type
for
all
data
generated
by
the
producer.
The
default
is
none
(i.e.
no
compression).
Valid
values
are
none,
gzip,
snappy,
or
lz
4
.
Compression
is
of
full
batches
of
data,
so
the
efficacy
of
batching
will
also
impact
the
compression
ratio
(more
batching
means
better
compression).
string
none
high
retries
Setting
a
value
greater
than
zero
will
cause
the
client
to
resend
any
record
whose
send
fails
with
a
potentially
transient
error.
Note
that
this
retry
is
no
different
than
if
the
client
resent
the
record
upon
receiving
the
error.
Allowing
retries
without
setting
max.in.flight.requests.per.connect
ionto
1
will
potentially
change
the
ordering
of
records
because
if
two
batches
are
sent
to
a
single
partition,
and
the
first
fails
and
is
retried
but
the
second
succeeds,
then
the
records
in
the
second
batch
may
appear
first.
int
0
[
0
,...,
2147
483647
]
high
ssl.key.p
assword
The
password
of
the
private
key
in
the
key
store
file.
This
is
optional
for
client.
passwor
d
null
high
ssl.keyst
ore.locat
The
location
of
the
key
store
file.
This
is
optional
for
client
and
can
string
null
high
5
ion
be
used
for
two-way
authentication
for
client.
ssl.keyst
ore.pass
word
The
store
password
for
the
key
store
file.This
is
optional
for
client
and
only
needed
if
ssl.keystore.location
is
configured.
passwor
d
null
high
ssl.trusts
tore.loca
tion
The
location
of
the
trust
store
file.
string
null
high
ssl.trusts
tore.pas
sword
The
password
for
the
trust
store
file.
passwor
d
null
high
batch.siz
e
The
producer
will
attempt
to
batch
records
together
into
fewer
requests
whenever
multiple
records
are
being
sent
to
the
same
partition.
This
helps
performance
on
both
the
client
and
the
server.
This
configuration
controls
the
default
batch
size
in
bytes.
No
attempt
will
be
made
to
batch
records
larger
than
this
size.
Requests
sent
to
brokers
will
contain
multiple
batches,
one
for
each
partition
with
data
available
to
be
sent.
A
small
batch
size
will
make
batching
less
common
and
may
reduce
throughput
(a
batch
size
of
zero
will
disable
batching
entirely).
A
very
large
batch
size
may
use
memory
a
bit
more
wastefully
as
we
will
always
allocate
a
buffer
of
th ifi d b t h i i
int
16384
[
0
,...]
medium
评论0