Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kafka versions #133

Closed
wants to merge 12 commits into from
Prev Previous commit
Next Next commit
Merge branch 'master' into kafka_versions
Conflicts:
	example.py
  • Loading branch information
Mark Roberts committed Apr 5, 2014
commit 66714cbfe8c7fa2205f300e262e1447c935c8055
50 changes: 38 additions & 12 deletions example.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,49 @@
#!/usr/bin/env python
import threading, logging, time

from kafka import Kafka081Client
from kafka.client import KafkaClient
from kafka.consumer import SimpleConsumer
from kafka.producer import SimpleProducer

def produce_example(client):
producer = client.simple_producer()
producer.send_messages('my-topic', "test")
class Producer(threading.Thread):
daemon = True

def consume_example(client):
consumer = client.simple_consumer("test-group", "my-topic")
for message in consumer:
print(message)
def run(self):
client = KafkaClient("localhost:9092")
producer = SimpleProducer(client)

while True:
producer.send_messages('my-topic', "test")
producer.send_messages('my-topic', "\xc2Hola, mundo!")

time.sleep(1)


class Consumer(threading.Thread):
daemon = True

def run(self):
client = KafkaClient("localhost:9092")
consumer = SimpleConsumer(client, "test-group", "my-topic")

for message in consumer:
print(message)

def main():
client = Kafka081Client("localhost:9092")
produce_example(client)
consume_example(client)
threads = [
Producer(),
Consumer()
]

for t in threads:
t.start()

time.sleep(5)


if __name__ == "__main__":
logging.basicConfig(level=logging.WARN)
logging.basicConfig(
format='%(asctime)s.%(msecs)s:%(name)s:%(thread)d:%(levelname)s:%(process)d:%(message)s',
level=logging.DEBUG
)
main()
You are viewing a condensed version of this merge commit. You can view the full changes here.