Customizing Consumer and Producer configuration
如果你希望对用于在 Kafka 中创建 ConsumerFactory
和 ProducerFactory
的消费者和生产者配置进行高级自定义,则可以实现以下自定义器。
If you want advanced customization of consumer and producer configuration that is used for creating ConsumerFactory
and ProducerFactory
in Kafka,
you can implement the following customizers.
-
ConsumerConfigCustomizer
-
ProducerConfigCustomizer
这两个接口都提供了一种配置用于消费者和生产者属性的 config map 的方式。例如,如果你希望访问在应用程序级别定义的 bean,可以在 configure
方法的实现中注入它。当绑定发现这些自定义器可用作 bean 时,它将在创建消费者和生产者工厂之前调用 configure
方法。
Both of these interfaces provide a way to configure the config map used for consumer and producer properties.
For example, if you want to gain access to a bean that is defined at the application level, you can inject that in the implementation of the configure
method.
When the binder discovers that these customizers are available as beans, it will invoke the configure
method right before creating the consumer and producer factories.
这两个接口都提供对绑定和目的地名称的访问,以便在自定义生成器和消费者属性时可以访问它们。
Both of these interfaces also provide access to both the binding and destination names so that they can be accessed while customizing producer and consumer properties.