[英]Specify compression type in Confluent Python Avro Producer
Is there a way to specify the compression.type
in producer configs while using the AvroProducer in Confluent's Kafka (python)? 在Confluent的Kafka(python)中使用AvroProducer时,是否可以在生产者配置中指定
compression.type
?
I tried the following: 我尝试了以下方法:
from confluent_kafka import avro
from confluent_kafka.avro import AvroProducer
from myconfigs import BOOTSTRAP_SERVER, SCHEMA_REGISTRY_URL, KEY_SCHEMA, VALUE_SCHEMA
avroProducer = AvroProducer({'bootstrap.servers': BOOTSTRAP_SERVER, 'schema.registry.url': SCHEMA_REGISTRY_URL, 'compression.type': 'gzip'},
default_key_schema=KEY_SCHEMA, default_value_schema=VALUE_SCHEMA)
Got the following error when running this: 运行此命令时出现以下错误:
Traceback (most recent call last):
File "confluent_click.py", line 47, in <module>
default_key_schema=KEY_SCHEMA, default_value_schema=VALUE_SCHEMA)
File "/usr/local/lib/python3.6/site-packages/confluent_kafka/avro/__init__.py", line 38, in __init__
super(AvroProducer, self).__init__(config)
cimpl.KafkaException: KafkaError{code=_INVALID_ARG,val=-186,str="No such configuration property: "compression.type""}
Also tried specifying compression_type = 'gzip'
as a param to AvroProducer()
as 还尝试将
compression_type = 'gzip'
指定为AvroProducer()
的参数, AvroProducer()
:
avroProducer = AvroProducer({'bootstrap.servers': BOOTSTRAP_SERVER, 'schema.registry.url': SCHEMA_REGISTRY_URL},
default_key_schema=KEY_SCHEMA, default_value_schema=VALUE_SCHEMA, compression_type='gzip')
I didn't expect this to succeed and it didn't. 我没想到这会成功,但没有成功。
Traceback (most recent call last):
File "confluent_click.py", line 47, in <module>
default_key_schema=KEY_SCHEMA, default_value_schema=VALUE_SCHEMA, compression_type='gzip')
TypeError: __init__() got an unexpected keyword argument 'compression_type'
How can I specify compression.type
in the producer? 如何在生产者中指定
compression.type
? I have not been able to find AvroProducer
's documentation. 我找不到
AvroProducer
的文档。
confluent-kafka-python's configuration property for setting the compression type is called compression.codec
for historical reasons (librdkafka, which predates the current Java client, based its initial configuration properties on the original Scala client which used compression.codec
). 出于历史原因,confluent-kafka-python的用于设置压缩类型的配置属性称为
compression.codec
(librdkafka,其早于当前Java客户端,其初始配置属性基于使用compression.codec
的原始Scala客户端)。
avroProducer = AvroProducer({'bootstrap.servers': BOOTSTRAP_SERVER, 'schema.registry.url': SCHEMA_REGISTRY_URL, 'compression.codec': 'gzip'},
default_key_schema=KEY_SCHEMA, default_value_schema=VALUE_SCHEMA)
Note: the v0.11.4 release of confluent-kafka-python adds a compression.type
alias. 注意:confluent-kafka-python v0.11.4版本添加了
compression.type
别名。
Full list of configuration settings here: https://github.com/edenhill/librdkafka/blob/master/CONFIGURATION.md 此处的配置设置的完整列表: https : //github.com/edenhill/librdkafka/blob/master/CONFIGURATION.md
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.