简体   繁体   中英

Kafka and Python

I have a python code that gets data from a API url

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).

Can someone help me in modifying the above code to include Kafka implementation to understand how the Kafka works ?

You're talking about reading messages from a Kafka topic, instead of your existing REST API.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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