The recent project always with Java, I write a Python programmer, in the face of complex data structure of Java code into Python code, is indeed a big problem, sometimes more or less will leave a bit of a hole, it seems to have to look at the Java Foundation. This is not the beginning to let us connect Kafka again today. The company's Kafka and zookeeper do a cluster, connection more trouble, specific how to use, Java that side do the package I also can not see, so only through simple communication.
Begin
Begin to find the standard library of Python connection Kafka, Kafka-python and Pykafka the former are more mature libraries, the latter is an upgraded version of Samsa, online to the article in Python Connection and use Kafka Using Samsa to connect zookeeper and then use Kafka cluster is very satisfying my needs, in the case of Pykafka also see ZK support, and Kafka-python does not have ZK support, so chose Pykafka as a connection library
Conceptual issues
Kafaka and zookeeper cluster, the use of Samsa when the producers and consumers are connected to the zookeeper, but I with the peak cloud (large data Daniel, Yun-Wei, Pan knock Widows ┕ low ǎ?? The sheath of Mei Neon is a coincidence?? Waved?? Afaka server list, consumers only use zookeeper. This also solves me to see the Pykafka document, only the consumer only then connects the zookeeper confusion, therefore solves, directly according to the document to start.
Producers
>>> from Pykafka import kafkaclient
>>> client = kafkaclient (hosts= "192.168.1.1:9092, 192.168.1.2:9092") # acceptable multiple client that's the point.
>>> client.topics # View all topic
>>> topic = client.topics[' my.test '] # Choose a topic
>>> producer = Topic.get_producer ()
>>> producer.produce ([' Test message ' + str (i * * 2) for I in range (4)]) # plus a STR official example py2.7 run
But
Consumers
>>> Balanced_consumer = Topic.get_balanced_consumer (
consumer_group= ' Testgroup ',
Auto_commit_enable=true, # No need to add consumer_group when set to Flase
Zookeeper_connect= ' Myzkclusternode1.com:2181,myzkclusternode2.com:2181/myzkchroot ' # here is the connection to multiple ZK
)