In the last episode, we wrote some simple code to produce messages in Apache Kafka via a RESTful API, implemented using the amazing Flask framework. If you have followed the post and written some code yourself, you might now want to put it into action. We assume you have Kafka fired up and written and started up a simple Flask app as described before.
To give our setup a test drive, let’s write a simple Kafka consumer in [Python][python] using the pykafka package. For the sake of simplicity, let’s just consume all messages in the topic named “test”, like so:
Running this script should print out all messages that get written to our test topic until the script is terminated. You can also use the console consumer (and producer) included with Kafka, but let’s in the spirit of DIY not do that.
To produce messages, we could write another Python script using pykafka, but this is not what we want. We wrote our Flask app such that we can produce messages using http. And being true hipsters, we will do it old school, using the console and cURL.
This should trigger the output
from your client script.
Consuming With Flask