22 lines
488 B
Python
22 lines
488 B
Python
# coding:utf-8
|
|
import time
|
|
import traceback
|
|
|
|
from kafka import KafkaProducer
|
|
|
|
from settings import settings
|
|
|
|
producer = KafkaProducer(**settings.KAFKA_PRODUCER_CONF)
|
|
|
|
msg = {
|
|
'#type': settings.STOP_SIGNAL,
|
|
'#time': int(time.time())
|
|
}
|
|
for i in range(0,16):
|
|
print(f'发送分区{i}')
|
|
future1 = producer.send(settings.GAME, msg, partition=i)
|
|
try:
|
|
future1.get(timeout=10)
|
|
except Exception as e: # 发送失败抛出kafka_errors
|
|
traceback.format_exc()
|