单节点多代理配置上的kafka使用者

时间:2017-04-03 12:00:10

标签: python apache-kafka

有人在使用单节点多代理设置的kafka python上工作吗?

我能够使用单节点单个代理设置生成和使用数据,但是当我将其更改为单个节点时,生成了多个代理数据并将其存储在主题中,但是当我运行消费者代码时,数据未被消耗。

对此有任何建议将不胜感激。提前谢谢!

注意:生产者,消费者和服务器属性等所有配置都经过验证,并且没有问题。

制片人代码:

from kafka.producer import KafkaProducer

def producer():
    data = {'desc' : 'testing', 'data' : 'testing single node multi broker'}
    topic = 'INTERNAL' 
    producer = KafkaProducer(value_serializer=lambda v:json.dumps(v).encode('utf-8'), bootstrap_servers=["localhost:9092","localhost:9093","localhost:9094"])

    producer.send(topic, data)

    producer.flush()

消费者代码:

from kafka.consumer import KafkaConsumer

def consumer():  
    topic = 'INTERNAL'
    consumer = KafkaConsumer(topic,bootstrap_servers=["localhost:9092","localhost:9093","localhost:9094"])


    for data in consumer:
        print data

服务器1配置:我添加了两个这样的服务器文件,其他代理的参数相同,但broker.idlog.dirs值不同。

broker.id=1
port=9092
num.network.threads=3
log.dirs=/tmp/kafka-logs-1
num.partitions=3
num.recovery.threads.per.data.dir=1
log.retention.hours=168
log.segment.bytes=1073741824
log.retention.check.interval.ms=300000
log.cleaner.enable=false
zookeeper.connect=localhost:2181
delete.topic.enable=true

制片人配置:

metadata.broker.list=localhost:9092,localhost:9093,localhost:9094

消费者配置:

zookeeper.connect=127.0.0.1:2181
zookeeper.connection.timeout.ms=6000

1 个答案:

答案 0 :(得分:1)

您是否收到了简单Kafka消费者的消息?

bin/kafka-console-consumer.sh –bootstrap-server localhost:9092,localhost:9093,localhost:9094 –topic INTERNAL –from-beginning

或者用这个:

bin/kafka-console-consumer.sh --zookeeper localhost:2181 --from-beginning --topic INTERNAL

如果您使用第二个命令获取消息,请尝试删除/tmp/log.dir中的/tmp/zookeepker/version-2/代理和日志文件<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/ScrollView01" android:layout_width="fill_parent" android:layout_height="fill_parent" > <RelativeLayout android:layout_width="match_parent" android:layout_height="508dp" android:background="#fff" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" > <Button android:id="@+id/pregnancy" android:layout_width="130dp" android:layout_height="100dp" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:background="@drawable/pregnancy" android:layout_marginTop="21dp" android:textColor="#fff" android:text="" /> <Button android:id="@+id/cancer" android:background="@drawable/cancer" android:layout_width="130dp" android:layout_height="100dp" android:layout_alignBottom="@+id/pregnancy" android:layout_alignParentRight="true" android:textColor="#fff" android:text="" /> <Button android:id="@+id/kids" android:layout_width="130dp" android:layout_height="100dp" android:layout_alignLeft="@+id/pregnancy" android:layout_below="@+id/pregnancy" android:textColor="#fff" android:background="@drawable/pediatrics" android:layout_marginTop="38dp" android:text="" /> <Button android:id="@+id/cardiology" android:layout_width="130dp" android:layout_height="100dp" android:layout_alignBaseline="@+id/kids" android:textColor="#fff" android:background="@drawable/cardiologist" android:layout_alignBottom="@+id/kids" android:layout_alignRight="@+id/cancer" android:text="" /> <Button android:id="@+id/neurology" android:layout_width="130dp" android:layout_height="100dp" android:background="@drawable/neurologista" android:layout_alignLeft="@+id/kids" android:textColor="#fff" android:layout_below="@+id/kids" android:layout_marginTop="38dp" android:text="" /> <Button android:id="@+id/ortho" android:layout_width="130dp" android:layout_height="100dp" android:background="@drawable/ortopedia" android:layout_alignBaseline="@+id/neurology" android:layout_alignBottom="@+id/neurology" android:layout_alignLeft="@+id/cardiology" android:textColor="#fff" android:text="" /> <Button android:id="@+id/dental" android:layout_width="130dp" android:layout_height="100dp" android:background="@drawable/dental" android:layout_alignLeft="@+id/neurology" android:layout_below="@+id/neurology" android:layout_marginTop="33dp" android:textColor="#fff" android:text="" /> <Button android:id="@+id/ent" android:layout_width="130dp" android:layout_height="100dp" android:background="@drawable/ent" android:layout_alignRight="@+id/ortho" android:textColor="#fff" android:layout_alignTop="@+id/dental" android:text="" /> <Button android:id="@+id/medicine" android:layout_width="130dp" android:layout_height="100dp" android:background="@drawable/medicine" android:layout_alignLeft="@+id/dental" android:layout_below="@+id/dental" android:layout_marginTop="43dp" android:textColor="#fff" android:text="" /> <Button android:id="@+id/dermatology" android:layout_width="130dp" android:layout_height="100dp" android:background="@drawable/dermatology" android:layout_alignBottom="@+id/medicine" android:layout_alignLeft="@+id/ent" android:textColor="#fff" android:text="" /> </RelativeLayout> </ScrollView> 。然后重新启动zookeeper和您的经纪人并再次创建您的主题。