【问题标题】:Default values for ProducerConfigs in Spring-Boot Apache KafkaSpring-Boot Apache Kafka 中 ProducerConfigs 的默认值
【发布时间】:2018-10-30 10:03:28
【问题描述】:

我有一个 Spring Boot 项目启动并运行,Kafka 正在实施。

我配置了一个生产者并发送了一条主题为“演示”的消息。
但我没有设置任何属性,例如
bootstrap.servers = [localhost:9092]
value.serializer = class org.apache.kafka .common.serialization.StringSerializer
我们通常在运行 kafka project-Producer 时设置的
我的项目成功运行,我能够使用该消息

我的问题是 Spring-Boot 是如何知道这些 ProducerConfig 属性的?有没有默认值

我在日志中也看到了

acks = 1
batch.size = 16384
bootstrap.servers = [localhost:9092]
buffer.memory = 33554432
client.id = 
compression.type = none
connections.max.idle.ms = 540000
enable.idempotence = false
interceptor.classes = null
key.serializer = class org.apache.kafka.common.serialization.StringSerializer
linger.ms = 0
max.block.ms = 60000
max.in.flight.requests.per.connection = 5
max.request.size = 1048576
metadata.max.age.ms = 300000
metric.reporters = []
metrics.num.samples = 2
metrics.recording.level = INFO
metrics.sample.window.ms = 30000
partitioner.class = class org.apache.kafka.clients.producer.internals.DefaultPartitioner
receive.buffer.bytes = 32768
reconnect.backoff.max.ms = 1000
reconnect.backoff.ms = 50
request.timeout.ms = 30000
retries = 0
retry.backoff.ms = 100
sasl.jaas.config = null
sasl.kerberos.kinit.cmd = /usr/bin/kinit
sasl.kerberos.min.time.before.relogin = 60000
sasl.kerberos.service.name = null
sasl.kerberos.ticket.renew.jitter = 0.05
sasl.kerberos.ticket.renew.window.factor = 0.8
sasl.mechanism = GSSAPI
security.protocol = PLAINTEXT
send.buffer.bytes = 131072
ssl.cipher.suites = null
ssl.enabled.protocols = [TLSv1.2, TLSv1.1, TLSv1]
ssl.endpoint.identification.algorithm = null
ssl.key.password = null
ssl.keymanager.algorithm = SunX509
ssl.keystore.location = null
ssl.keystore.password = null
ssl.keystore.type = JKS
ssl.protocol = TLS
ssl.provider = null
ssl.secure.random.implementation = null
ssl.trustmanager.algorithm = PKIX
ssl.truststore.location = null
ssl.truststore.password = null
ssl.truststore.type = JKS
transaction.timeout.ms = 60000
transactional.id = null
value.serializer = class org.apache.kafka.common.serialization.StringSerializer

这些属性在哪里设置?

【问题讨论】:

    标签: spring-boot apache-kafka spring-kafka


    【解决方案1】:

    看看org.apache.kafka.clients.producer.ProducerConfig。 在那里你可以发现一些属性有默认值

    define(BATCH_SIZE_CONFIG, Type.INT, 16384, atLeast(0), Importance.MEDIUM, BATCH_SIZE_DOC)
    

    【讨论】:

    • 是的,我看到了 ProducerConfig 类,但没有找到类似 bootstrap.servers = [localhost:9092]
    • 此表也显示默认值:kafka.apache.org/documentation/#producerconfigs。 Spring Boot 对 ProducerConfig 一无所知,您在日志中看到的内容来自 Kafka 客户端,而不是 Boot。
    • Boot 应用了一些默认值(序列化器/反序列化器、引导服务器)l 请参阅我的答案以获取链接。
    • @ArtemBilan 我没有在 ProducerConfig 类中找到 bootstrap.servers = localhost:9092 的默认值
    • 对。这个来自 Spring Boot。的确。见这里:github.com/spring-projects/spring-boot/blob/master/…
    【解决方案2】:

    请参阅Boot documentation

    向下滚动到 Kafka 并单击 link to KafkaProperties

    【讨论】:

      猜你喜欢
      • 2019-02-21
      • 1970-01-01
      • 2020-10-08
      • 2018-09-21
      • 1970-01-01
      • 2020-07-11
      • 2022-08-03
      • 2021-08-30
      • 2021-05-28
      相关资源
      最近更新 更多