Consumer配置

半兽人 发表于: 2015-03-09   最后更新时间: 2017-09-25 20:07:13  
{{totalSubscript}} 订阅, 15,760 游览

3.2 Consumer 配置


The essential consumer configurations are the following:
基本消费配置如下:

  • group.id
  • zookeeper.connect

More details about consumer configuration can be found in the scala classkafka.consumer.ConsumerConfig.
更多细节可以查看  scala类:  kafka.consumer.ConsumerConfig

Property Default Description
group.id
A string that uniquely identifies the group of consumer processes to which this consumer belongs. By setting the same group id multiple processes indicate that they are all part of the same consumer group.
用来唯一标识consumer进程所在组的字符串,如果设置同样的group  id,表示这些processes都是属于同一个consumer  group
zookeeper.connect
Specifies the ZooKeeper connection string in the formhostname:portwhere host and port are the host and port of a ZooKeeper server. To allow connecting through other ZooKeeper nodes when that ZooKeeper machine is down you can also specify multiple hosts in the formhostname1:port1,hostname2:port2,hostname3:port3.

The server may also have a ZooKeeper chroot path as part of it's ZooKeeper connection string which puts its data under some path in the global ZooKeeper namespace. If so the consumer should use the same chroot path in its connection string. For example to give a chroot path of/chroot/pathyou would give the connection string ashostname1:port1,hostname2:port2,hostname3:port3/chroot/path.
指定zookeeper的连接的字符串,格式是hostname:port,此处host和port都是zookeeper server的host和port,为避免某个zookeeper 机器宕机之后失联,你可以指定多个hostname:port,使用逗号作为分隔:
hostname1:port1,hostname2:port2,hostname3:port3
可以在zookeeper连接字符串中加入zookeeper的chroot路径,此路径用于存放他自己的数据,方式:
hostname1:port1,hostname2:port2,hostname3:port3/chroot/path)

consumer.id null

Generated automatically if not set.
不需要设置,一般自动产生

socket.timeout.ms 30 * 1000 The socket timeout for network requests. The actual timeout set will be max.fetch.wait + socket.timeout.ms.
网络请求的超时限制。真实的超时限制是   max.fetch.wait+socket.timeout.ms
socket.receive.buffer.bytes 64 * 1024 The socket receive buffer for network requests
socket用于接收网络请求的缓存大小
fetch.message.max.bytes 1024 * 1024 The number of byes of messages to attempt to fetch for each topic-partition in each fetch request. These bytes will be read into memory for each partition, so this helps control the memory used by the consumer. The fetch request size must be at least as large as the maximum message size the server allows or else it is possible for the producer to send messages larger than the consumer can fetch.
每次fetch请求中,针对每次fetch消息的最大字节数。这些字节将会督导用于每个partition的内存中,因此,此设置将会控制 consumer所使用的memory大小。这个fetch请求尺寸必须至少和server允许的最大消息尺寸相等,否则,producer可能发送的消 息尺寸大于consumer所能消耗的尺寸。
num.consumer.fetchers 1 The number fetcher threads used to fetch data.
用于fetch数据的fetcher线程数
auto.commit.enable true If true, periodically commit to ZooKeeper the offset of messages already fetched by the consumer. This committed offset will be used when the process fails as the position from which the new consumer will begin.
如果为真,consumer所fetch的消息的offset将会自动的同步到zookeeper。这项提交的offset将在进程挂掉时,由新的consumer使用
auto.commit.interval.ms 60 * 1000 The frequency in ms that the consumer offsets are committed to zookeeper.
consumer向zookeeper提交offset的频率,单位是ms

queued.max.message.chunks 2 Max number of message chunks buffered for consumption. Each chunk can be up to fetch.message.max.bytes.
用于缓存消息的最大数目,以供consumption。每个chunk必须和fetch.message.max.bytes相同
rebalance.max.retries 4 When a new consumer joins a consumer group the set of consumers attempt to "rebalance" the load to assign partitions to each consumer. If the set of consumers changes while this assignment is taking place the rebalance will fail and retry. This setting controls the maximum number of attempts before giving up.
当新的consumer加入到consumer  group时,consumers集合试图重新平衡分配到每个consumer的partitions数目。如果consumers集合改变了,当分配正在执行时,这个重新平衡会失败并重入,放弃尝试的最大次数
fetch.min.bytes 1 The minimum amount of data the server should return for a fetch request. If insufficient data is available the request will wait for that much data to accumulate before answering the request.
每次fetch请求时,server应该返回的最小字节数。如果没有足够的数据返回,请求会等待,直到足够的数据才会返回。
fetch.wait.max.ms 100 The maximum amount of time the server will block before answering the fetch request if there isn't sufficient data to immediately satisfy fetch.min.bytes
如果没有足够的数据能够满足fetch.min.bytes,则此项配置是指在应答fetch请求之前,server会阻塞的最大时间。
rebalance.backoff.ms 2000 Backoff time between retries during rebalance.
在重试reblance之前backoff时间
refresh.leader.backoff.ms 200 Backoff time to wait before trying to determine the leader of a partition that has just lost its leader.
在试图确定某个partition的leader是否失去他的leader地位之前,需要等待的backoff时间
auto.offset.reset largest

What to do when there is no initial offset in ZooKeeper or if an offset is out of range:
* smallest : automatically reset the offset to the smallest offset
* largest : automatically reset the offset to the largest offset
* anything else: throw exception to the consumer
zookeeper中没有初始化的offset时,如果offset是以下值的回应:
* smallest:自动复位offset为smallest的offset
* largest:自动复位offset为largest的offset
* anything  else:向consumer抛出异常

consumer.timeout.ms -1 Throw a timeout exception to the consumer if no message is available for consumption after the specified interval
如果没有消息可用,即使等待特定的时间之后也没有,则抛出超时异常
exclude.internal.topics true Whether messages from internal topics (such as offsets) should be exposed to the consumer.
是否将内部topics的消息暴露给consumer
partition.assignment.strategy range Select a strategy for assigning partitions to consumer streams. Possible values: range, roundrobin.
选择向consumer 流分配partitions的策略,可选值:range,roundrobin
client.id group id value The client id is a user-specified string sent in each request to help trace calls. It should logically identify the application making the request.
是用户特定的字符串,用来在每次请求中帮助跟踪调用。它应该可以逻辑上确认产生这个请求的应用
zookeeper.session.timeout.ms  6000 ZooKeeper session timeout. If the consumer fails to heartbeat to ZooKeeper for this period of time it is considered dead and a rebalance will occur.
zookeeper 会话的超时限制。如果consumer在这段时间内没有向zookeeper发送心跳信息,则它会被认为挂掉了,并且reblance将会产生
zookeeper.connection.timeout.ms 6000 The max time that the client waits while establishing a connection to zookeeper.
客户端在建立通zookeeper连接中的最大等待时间
zookeeper.sync.time.ms  2000 How far a ZK follower can be behind a ZK leader
ZK follower可以落后ZK leader的最大时间
offsets.storage zookeeper Select where offsets should be stored (zookeeper or kafka).
用于存放offsets的地点: zookeeper或者kafka
offsets.channel.backoff.ms 1000 The backoff period when reconnecting the offsets channel or retrying failed offset fetch/commit requests.
重新连接offsets channel或者是重试失败的offset的fetch/commit请求的backoff时间
offsets.channel.socket.timeout.ms 10000 Socket timeout when reading responses for offset fetch/commit requests. This timeout is also used for ConsumerMetadata requests that are used to query for the offset manager.
当读取offset的fetch/commit请求回应的socket 超时限制。此超时限制是被consumerMetadata请求用来请求offset管理
offsets.commit.max.retries 5 Retry the offset commit up to this many times on failure. This retry count only applies to offset commits during shut-down. It does not apply to commits originating from the auto-commit thread. It also does not apply to attempts to query for the offset coordinator before committing offsets. i.e., if a consumer metadata request fails for any reason, it will be retried and that retry does not count toward this limit.
重试offset commit的次数。这个重试只应用于offset  commits在shut-down之间。
dual.commit.enabled true If you are using "kafka" as offsets.storage, you can dual commit offsets to ZooKeeper (in addition to Kafka). This is required during migration from zookeeper-based offset storage to kafka-based offset storage. With respect to any given consumer group, it is safe to turn this off after all instances within that group have been migrated to the new version that commits offsets to the broker (instead of directly to ZooKeeper).
如果使用“kafka”作为offsets.storage,你可以二次提交offset到zookeeper(还有一次是提交到kafka)。在 zookeeper-based的offset  storage到kafka-based的offset storage迁移时,这是必须的。对任意给定的consumer  group来说,比较安全的建议是当完成迁移之后就关闭这个选项
partition.assignment.strategy range

Select between the "range" or "roundrobin" strategy for assigning partitions to consumer streams.

The round-robin partition assignor lays out all the available partitions and all the available consumer threads. It then proceeds to do a round-robin assignment from partition to consumer thread. If the subscriptions of all consumer instances are identical, then the partitions will be uniformly distributed. (i.e., the partition ownership counts will be within a delta of exactly one across all consumer threads.) Round-robin assignment is permitted only if: (a) Every topic has the same number of streams within a consumer instance (b) The set of subscribed topics is identical for every consumer instance within the group.

Range partitioning works on a per-topic basis. For each topic, we lay out the available partitions in numeric order and the consumer threads in lexicographic order. We then divide the number of partitions by the total number of consumer streams (threads) to determine the number of partitions to assign to each consumer. If it does not evenly divide, then the first few consumers will have one extra partition.
在“range”和“roundrobin”策略之间选择一种作为分配partitions给consumer 数据流的策略; 循环的partition分配器分配所有可用的partitions以及所有可用consumer  线程。它会将partition循环的分配到consumer线程上。如果所有consumer实例的订阅都是确定的,则partitions的划分是 确定的分布。循环分配策略只有在以下条件满足时才可以:(1)每个topic在每个consumer实力上都有同样数量的数据流。(2)订阅的topic 的集合对于consumer  group中每个consumer实例来说都是确定的。

More details about consumer configuration can be found in the scala classkafka.consumer.ConsumerConfig.
更多细节可以查看  scala类:  kafka.consumer.ConsumerConfig

更新于 2017-09-25

查看history更多相关的文章或提一个关于history的问题,也可以与我们一起分享文章