該文檔只是向前您到Apache卡夫卡的Javadoc ProducerConfig,因爲是包含了一些你可以爲你的akka.kafka.producer.kafka-clients
配置部分中鍵使用常量。
擴展從文檔的參考配置,一個例子是:
# Properties for akka.kafka.ProducerSettings can be
# defined in this section or a configuration section with
# the same layout.
akka.kafka.producer {
# Tuning parameter of how many sends that can run in parallel.
parallelism = 100
# How long to wait for `KafkaProducer.close`
close-timeout = 60s
# Fully qualified config path which holds the dispatcher configuration
# to be used by the producer stages. Some blocking may occur.
# When this value is empty, the dispatcher configured for the stream
# will be used.
use-dispatcher = "akka.kafka.default-dispatcher"
# Properties defined by org.apache.kafka.clients.producer.ProducerConfig
# can be defined in this configuration section.
kafka-clients {
bootstrap.servers = "localhost:9092"
enable.auto.commit = true
auto.commit.interval.ms = 10000
acks = "all"
retries = 0
batch.size = 16384
}
}
您application.conf
文件的內容將被默認加載你的ActorSystem
,所以每當你創建一個ProducerSettings
對象按如下,它應該從akka.kafka.producer
進行配置。您不需要將配置顯式傳遞給構造函數。
val producerSettings = ProducerSettings(system, new ByteArraySerializer, new StringSerializer)
感謝您的評論,我瞭解了這一部分,我想知道如何使用此配置文件來初始化/設置'ProducerSettings'屬性。 – Explorer
我已經更新了答案。實質上,該配置應該由Akka自動加載,不需要做任何明確的.. –
它的工作,我沒有在我的課程路徑資源目錄。謝謝 – Explorer