-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
1,981 additions
and
877 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Project/People/Companies using kafka-python | ||
|
||
If you're using this library and care to give us a shout out, please fork the project, | ||
add yourself here, and submit a pull request. Thanks! | ||
|
||
* [@mumrah](https://github.com/mumrah), adding myself as an example |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,48 @@ | ||
import logging | ||
#!/usr/bin/env python | ||
import threading, logging, time | ||
|
||
from kafka.client import KafkaClient, FetchRequest, ProduceRequest | ||
from kafka.client import KafkaClient | ||
from kafka.consumer import SimpleConsumer | ||
from kafka.producer import SimpleProducer | ||
|
||
def produce_example(client): | ||
producer = SimpleProducer(client, "my-topic") | ||
producer.send_messages("test") | ||
class Producer(threading.Thread): | ||
daemon = True | ||
|
||
def consume_example(client): | ||
consumer = SimpleConsumer(client, "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 = KafkaClient("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.DEBUG) | ||
logging.basicConfig( | ||
format='%(asctime)s.%(msecs)s:%(name)s:%(thread)d:%(levelname)s:%(process)d:%(message)s', | ||
level=logging.DEBUG | ||
) | ||
main() |
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
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
Oops, something went wrong.