简体   繁体   English

Kafka和Python

[英]Kafka and Python

I have a python code that gets data from a API url 我有一个从API网址获取数据的python代码

def get_api_request(zipcode):
    request_url = 'https://www.zipcodeapi.com/rest/<apikey>/info.json/'+ str(zipcode)+'/degrees'
    request = Request(request_url)

    try:
        response = urlopen(request)
        data = response.read()
        data = json.loads(data)
        city=data['city']
        state=data['state']
        update_city(city,state)

    except (Exception) as error:
            print(error)

The above code basically gets the city and state for the given zip code. 上面的代码基本上获取了给定邮政编码的城市和州。 Being new to Kafka, I'm trying to implement this same process through Kafka (to manage large data sets). 作为Kafka的新手,我正在尝试通过Kafka(管理大型数据集)实施相同的过程。

Can someone help me in modifying the above code to include Kafka implementation to understand how the Kafka works ? 有人可以帮我修改上面的代码以包括Kafka实现,以了解Kafka的工作原理吗?

You're talking about reading messages from a Kafka topic, instead of your existing REST API. 您是在谈论从Kafka主题中读取消息,而不是从现有的REST API中读取消息。

Check out https://www.confluent.io/blog/introduction-to-apache-kafka-for-python-programmers/ and https://github.com/confluentinc/confluent-kafka-python . 查看https://www.confluent.io/blog/introduction-to-apache-kafka-for-python-programmers/https://github.com/confluentinc/confluent-kafka-python

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM