簡體   English   中英

無法使用 confluent-kafka-python 從 Kafka Topic 消費到新的消費者組

[英]Cannot consume from Kafka Topic using confluent-kafka-python to a new consumer-group

我正在嘗試使用 confluent-kafka-python 從 Kafka Topic 消費到全新的消費者組(如下所示示例中的 GROUP_NAME_CONNECT5)。 它似乎不起作用,除非我首先使用這個新的消費者組使用 kafka-console-consumer ! 在我使用 kafka-console-consumer 消費 1 次后,confluent-kafka-python 消費者工作正常! 知道為什么嗎?

特性:

[卡夫卡]

bootstrap_servers=

ssl_ca_location=

max_wait_cycles=30

group_name=GROUP_NAME_CONNECT5

client_id=CLIENT_ID

auto_commit_interval_ms=5000

代碼:

kafkaConsumerConfig = {
    'bootstrap.servers': config.BOOTSTRAP_SERVERS,
    'group.id': config.GROUP_NAME,
    'client.id': config.CLIENT_ID,
    'session.timeout.ms': 60000,
    'heartbeat.interval.ms': 3000,

    'security.protocol': 'SASL_SSL',
    'sasl.kerberos.service.name': 'kafka',

    'sasl.mechanisms': 'GSSAPI',
    'ssl.ca.location': config.SSL_CA_LOCATION,
    'sasl.kerberos.kinit.cmd': 'kinit -S {0} {1} -k -t {2}'.format(config.KEYTAB_PRINCIPAL, config.KEYTAB_USER, config.KEYTAB_PATH),
    'default.topic.config': {
        'enable.auto.commit': 'false',
        'enable.auto.offset.store': 'false'
    }

c = Consumer(**self.kafkaConsumerConfig)

c.subscribe([self.TOPIC_NAME])

while True:
    kafka_msg = c.poll(1.0)
    process_message(kafka_msg)

日志:運行 Python Consumer 5 分鍾后(然后將其殺死)。 Python 消費者無法消費任何消息!

%7|1579623452.300|INIT|CLIENT_ID#consumer-1| [thrd:app]: librdkafka v1.2.1 (0x10201ff) CLIENT_ID#consumer-1 初始化 (builtin.features gzip,snappy,ssl,sasl,regex,lz4,sasl_gssapi,sasl_plain,sasl_scram,GNU_plugins,GUNFIGAUST LDS LIBDL 插件 ZLIB SSL SASL_CYRUS HDRHISTOGRAM SNAPPY SOCKEM SASL_SCRAM SASL_OAUTHBEARER CRC32C_HW,調試 0x2000) %7|1579623452.303|訂閱|CLIENT_ID|#consumer [thrd:main]:組“GROUP_NAME_CONNECT5”:訂閱1個主題的新訂閱(加入狀態初始化)%7|1579623452.303|REBALANCE|CLIENT_ID#consumer-1| [thrd:main]:組“GROUP_NAME_CONNECT5”正在重新平衡狀態 init (join-state init) 沒有分配:取消訂閱 %7|1579623453.441|JOIN|CLIENT_ID#consumer-1| [thrd:main]:組“GROUP_NAME_CONNECT5”:推遲加入,直到有最新的元數據可用 %7|1579623453.443|REJOIN|CLIENT_ID#consumer-1| [thrd:main]:組“GROUP_NAME_CONNECT5”:訂閱因元數據更改而更新:重新加入組 %7|1579623453.443|REBALANCE|CLIENT_ID#consumer-1| [thrd:main]:組“GROUP_NAME_CONNECT5”正在重新平衡狀態(加入狀態初始化)而沒有分配:組重新加入 %7|1579623455.300|JOIN|CLIENT_ID#consumer-1| [thrd:main]: sasl_ssl://xxxx/159: 加入群組“GROUP_NAME_CONNECT5”,訂閱了 1 個主題 %7|1579623458.305|ASSIGNOR|CLIENT_ID#consumer-1| [thrd:main]:組“GROUP_NAME_CONNECT5”:“范圍”分配器為 1 個成員運行 %7|1579623458.309|ASSIGN|CLIENT_ID#consumer-1| [thrd:main]:組“GROUP_NAME_CONNECT5”:新分配的 8 個分區處於連接狀態 wait-assign-rebalance_cb %7|1579623458.309|OFFSET|CLIENT_ID#consumer-1| [thrd:main]: GroupCoordinator/159: 獲取 8/8 分區的已提交偏移量 %7|1579623458.312|FETCH|CLIENT_ID#consumer-1| [thrd:main]:分區 che_silo_cnsld_rpt_mthly [2] 從偏移 123698 %7|1579623458.313|FETCH|CLIENT_ID#consumer-1| 開始提取 [thrd:main]:分區 che_silo_cnsld_rpt_mthly [7] 從偏移 116555 %7|1579623458.465|FETCH|CLIENT_ID#consumer-1| 開始提取 [thrd:main]: 分區 che_silo_cnsld_rpt_mthly [4] 從偏移 106800 %7|1579623458.484|FETCH|CLIENT_ID#consumer-1| 開始提取 [thrd:main]:分區 che_silo_cnsld_rpt_mthly [1] 從偏移 107557 %7|1579623458.485|FETCH|CLIENT_ID#consumer-1| 開始提取 [thrd:main]:分區 che_silo_cnsld_rpt_mthly [6] 從偏移 109805 %7|1579623458.486|FETCH|CLIENT_ID#consumer-1| 開始提取 [thrd:main]: 分區 che_silo_cnsld_rpt_mthly [0] 從偏移 91465 %7|1579623458.487|FETCH|CLIENT_ID#consumer-1| 開始提取 [thrd:main]: 分區 che_silo_cnsld_rpt_mthly [3] 從偏移 102042 %7|1579623458.487|FETCH|CLIENT_ID#consumer-1| 開始提取 [thrd:main]: 分區 che_silo_cnsld_rpt_mthly [5] 從偏移 117214 處開始提取

運行 kafka-consumer-groups

../bin/kafka-consumer-groups.sh --bootstrap-server xxx --command-config producer.properties --group GROUP_NAME_CONNECT5 --describe

消費者組“GROUP_NAME_CONNECT5”沒有活躍成員。

然后,我使用相同的新消費者組 (GROUP_NAME_CONNECT5) 運行 kafka-console-consumer。 它消耗了 Topic 中的所有消息。

../bin/kafka-consumer-groups.sh --bootstrap-server xxx --command-config producer.properties --group GROUP_NAME_CONNECT5 --describe OpenJDK 64 位服務器虛擬機警告:如果處理器數量預計會增加從一開始,那么您應該使用 -XX:ParallelGCThreads=N 適當地配置並行 GC 線程的數量 消費者組 'GROUP_NAME_CONNECT5' 沒有活動成員。

主題划分CURRENT-OFFSET LOG-END-OFFSET LAG CONSUMER-ID HOST CLIENT-ID che_silo_cnsld_rpt_mthly 1 112644 112644 0 - - - che_silo_cnsld_rpt_mthly 5 123099 123099 0 - - - che_silo_cnsld_rpt_mthly 0 95715 95715 0 - - - che_silo_cnsld_rpt_mthly 3 106932 106932 0 - - - che_silo_cnsld_rpt_mthly 4 112588 112588 0 - - - che_silo_cnsld_rpt_mthly 7 122047 122047 0 - - - che_silo_cnsld_rpt_mthly 2 40 12990-cnsld_rpt_mthly 2 11290thly 2 112990-cn15 -cn15 _sild_rpt_mthly 7 122047

然后我在主題中生成一些新消息並運行 python-consumer...而且,這次 python-consumer 運行成功!

%7|1579624630.644|INIT|CLIENT_ID#consumer-1| [thrd:app]: librdkafka v1.2.1 (0x10201ff) CLIENT_ID#consumer-1 初始化 (builtin.features gzip,snappy,ssl,sasl,regex,lz4,sasl_gssapi,sasl_plain,sasl_scram,GNU_plugins,GUNFIGAUST LDS LIBDL 插件 ZLIB SSL SASL_CYRUS HDRHISTOGRAM SNAPPY SOCKEM SASL_SCRAM SASL_OAUTHBEARER CRC32C_HW,調試 0x2000) %7|1579624630.648|訂閱|CLIENT_ID|#consumer [thrd:main]:組“GROUP_NAME_CONNECT5”:訂閱1個主題的新訂閱(加入狀態初始化)%7|1579624630.648|REBALANCE|CLIENT_ID#consumer-1| [thrd:main]:組“GROUP_NAME_CONNECT5”正在重新平衡狀態 init (join-state init) 沒有分配:取消訂閱 %7|1579624631.807|JOIN|CLIENT_ID#consumer-1| [thrd:main]:組“GROUP_NAME_CONNECT5”:推遲加入,直到有最新的元數據可用 %7|1579624631.808|REJOIN|CLIENT_ID#consumer-1| [thrd:main]:組“GROUP_NAME_CONNECT5”:訂閱因元數據更改而更新:重新加入組 %7|1579624631.808|REBALANCE|CLIENT_ID#consumer-1| [thrd:main]:組“GROUP_NAME_CONNECT5”正在重新平衡狀態(加入狀態初始化)而沒有分配:組重新加入 %7|1579624633.644|JOIN|CLIENT_ID#consumer-1| [thrd:main]: sasl_ssl://cilhdkfs0304.sys.cigna.com:9095/159: 加入群組“GROUP_NAME_CONNECT5”,訂閱了 1 個主題 %7|1579624636.650|ASSIGNOR|CLIENT_ID|#consumer [thrd:main]:組“GROUP_NAME_CONNECT5”:“范圍”分配者為 1 個成員運行 %7|1579624636.654|ASSIGN|CLIENT_ID#consumer-1| [thrd:main]:組“GROUP_NAME_CONNECT5”:新分配的 8 個分區處於連接狀態 wait-assign-rebalance_cb %7|1579624636.654|OFFSET|CLIENT_ID#consumer-1| [thrd:main]: GroupCoordinator/159: 獲取 8/8 分區的提交偏移量 %7|1579624636.656|FETCH|CLIENT_ID#consumer-1| [thrd:main]: 分區 che_silo_cnsld_rpt_mthly [0] 從偏移 91465 %7|1579624636.656|FETCH|CLIENT_ID#consumer-1| 開始提取 [thrd:main]: 分區 che_silo_cnsld_rpt_mthly [1] 從偏移 107557 %7|1579624636.656|FETCH|CLIENT_ID#consumer-1| 開始提取 [thrd:main]:分區 che_silo_cnsld_rpt_mthly [2] 從偏移 123698 %7|1579624636.656|FETCH|CLIENT_ID#consumer-1| 開始提取 [thrd:main]: 分區 che_silo_cnsld_rpt_mthly [3] 從偏移 102042 %7|1579624636.656|FETCH|CLIENT_ID#consumer-1| 開始提取 [thrd:main]: 分區 che_silo_cnsld_rpt_mthly [4] 從偏移 106800 %7|1579624636.656|FETCH|CLIENT_ID#consumer-1| 開始提取 [thrd:main]: 分區 che_silo_cnsld_rpt_mthly [5] 從偏移 117214 %7|1579624636.656|FETCH|CLIENT_ID#consumer-1| 開始提取 [thrd:main]: 分區 che_silo_cnsld_rpt_mthly [6] 從偏移 109805 %7|1579624636.656|FETCH|CLIENT_ID#consumer-1| 開始提取 [thrd:main]: 分區 che_silo_cnsld_rpt_mthly [7] 從偏移 116555 處開始獲取

我猜您的問題與“auto.offset.reset”配置有關。 當您的消費者加入集群時,此配置定義您的消費者將從哪個偏移量開始消費。 嘗試放置:

"auto.offset.reset": "earliest"

此配置將使您的消費者從第一個(最早的)偏移量/消息開始消費。 默認配置為“最大”,這意味着當主題上有新消息可用時,消費者將開始消費。 檢查這個以獲取更多詳細信息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM