blob: 1e4bd8b7da56541a37db1081340c2e944fb87815 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
import logging
from kafka.client import KafkaClient, FetchRequest, ProduceRequest
from kafka.consumer import SimpleConsumer
from kafka.producer import SimpleProducer
def produce_example(client):
producer = SimpleProducer(client, "my-topic")
producer.send_message("test")
def consume_example(client):
consumer = SimpleConsumer(client, "test-group", "my-topic")
for message in consumer:
print(message)
def main():
client = KafkaClient("localhost", 9092)
produce_example(client)
consume_example(client)
if __name__ == "__main__":
logging.basicConfig(level=logging.DEBUG)
main()
|