Last active
December 11, 2015 00:32
-
-
Save saran87/244273071cb4518daafd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging as log | |
import time | |
import multiprocessing | |
from pykafka import KafkaClient | |
from pykafka.common import OffsetType | |
log.basicConfig(level=log.DEBUG) | |
client = KafkaClient(hosts="127.0.0.1:9092") | |
def run_consumer(): | |
topic = client.topics['test2'] | |
log.info("Got the topic") | |
consumer = topic.get_simple_consumer("test") | |
log.info("initialized consumer") | |
consumer.start() | |
time.sleep(2) | |
while True: | |
try: | |
message = consumer.consume() | |
if message: | |
print message.value | |
except: | |
break | |
def run_consumers(): | |
t = multiprocessing.Process(target=run_consumer, name="consumer") | |
t.daemon = False # True | |
t.start() | |
t.join() | |
if __name__ == "__main__": | |
run_consumers() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment