无法在Kafka中发布

时间:2018-06-30 06:15:35

标签: apache-kafka kafka-python

我要在Kafka主题中发布 我无法这样做,程序停止了。 我收到此错误:

  

KafkaTimeoutError:60.0秒后无法更新元数据。

def saveResults(response):
    entities_tweet = response["entities"]
    for entity in entities_tweet:
        try:
            for i in entity_dict:
                for j in entity_dict[i]:
                    if(entity["text"] in j):
                        entity["tweet"] = response["tweet"]
                        entity["tweetId"] = response["tweetId"]
                        entity["timeStamp"] = response["timeStamp"]
                        #entity["userProfile"] = response["userProfile"]
                        future = producer.send('argentina-iceland-june-16-watson', bytes(entity))
                        print("Published.")
                    else:
                        print("All ignored.")
                        future = producer.send('argentina-iceland-june-16-watson', bytes(entity))
                        print("Published")
        except Exception as e:
            print (e)
        finally:
            producer.flush()

但是,这是可行的:

from kafka import KafkaProducer
from kafka.errors import KafkaError

producer = KafkaProducer(bootstrap_servers=['broker1:1234'])

# Asynchronous by default
future = producer.send('my-topic', b'raw_bytes')

1 个答案:

答案 0 :(得分:0)

您似乎使用了错误的boostrap服务器,应该是broker1:9092而不是broker1:1234 ...