Commit aded7896 authored by 张彦钊's avatar 张彦钊

change test file

parent ec4c353c
...@@ -6,21 +6,27 @@ import pickle ...@@ -6,21 +6,27 @@ import pickle
import time import time
from kafka import KafkaProducer from kafka import KafkaProducer
def on_send_success(): def on_send_success():
print("succeed") print("succeed")
return 1 return 1
def on_send_error(): def on_send_error():
print("fail") print("fail")
return 0 return 0
if __name__ == "__main__": if __name__ == "__main__":
producer = KafkaProducer(bootstrap_servers=['172.16.44.25:9092'],key_serializer=lambda k: pickle.dumps(k),value_serializer=lambda v: pickle.dumps(v)) producer = KafkaProducer(bootstrap_servers=['172.16.44.25:9092'],key_serializer=lambda k: pickle.dumps(k),value_serializer=lambda v: pickle.dumps(v))
print("hajs") print("hajs")
producer.send(topic = "test_topic", key = "hello", value = "world")\ future = producer.send(topic= "test_topic", key = "hello", value = "world")
.add_callback(on_send_success).add_errback(on_send_error) try:
producer.flush() record_metadata = future.get(timeout=10)
producer.close() print(12)
except kafka_errors as e:
print(str(e))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment