wvanbergen/kafka — pull request #7 by seunglee150 (2014-06-24 07:58:35+00:00)
Title: graceful zookeeper close

close zookeeper gracefully so that rebalance works well.

this patch needed if kafka partition is more than one.

### zookeeper log
* before
```
2014-06-24 16:49:37,713 WARN org.apache.zookeeper.server.NIOServerCnxn: caught end of stream exception
EndOfStreamException: Unable to read additional data from client sessionid 0x1468ed314d95c04, likely client has closed socket
at org.apache.zookeeper.server.NIOServerCnxn.doIO(NIOServerCnxn.java:220)
at org.apache.zookeeper.server.NIOServerCnxnFactory.run(NIOServerCnxnFactory.java:208)
at java.lang.Thread.run(Thread.java:744)
```

* after
```
2014-06-24 16:53:18,034 INFO org.apache.zookeeper.server.NIOServerCnxn: Closed socket connection for client /172.29.11.189:52431 which had sessionid 0x1468ed314d95c0f
```

### ConsumerGroup example log after patch

* terminal 1
```
[Sarama] 2014/06/24 16:56:00 Start consuming partition 1...
[Sarama] 2014/06/24 16:56:01 Start consuming partition 1...
[Sarama] 2014/06/24 16:56:02 Start consuming partition 1...
[Sarama] 2014/06/24 16:56:03 Start consuming partition 1...
^C[Sarama] 2014/06/24 16:56:03 Releasing claim for partition 1...
2014/06/24 16:56:03 Processed 0 events.
```

* terminal 2
```
[Sarama] 2014/06/24 16:56:00 Start consuming partition 0...
[Sarama] 2014/06/24 16:56:01 Start consuming partition 0...
[Sarama] 2014/06/24 16:56:02 Start consuming partition 0...
[Sarama] 2014/06/24 16:56:03 Start consuming partition 0...
[Sarama] 2014/06/24 16:56:03 Releasing claim for partition 0...
[Sarama] 2014/06/24 16:56:03 Requesting to resume from offset 495
[Sarama] 2014/06/24 16:56:04 Requesting to resume from offset 182
[Sarama] 2014/06/24 16:56:04 Unexpected error processing FetchRequest; disconnecting broker nuk158.kr2.iwilab.com:9092: kafka: broker: not connected
[Sarama] 2014/06/24 16:56:04 Disconnecting Broker 3
[Sarama] 2014/06/24 16:56:04 Fetching metadata from broker nuk155.kr2.iwilab.com:9092
[Sarama] 2014/06/24 16:56:04 Failed to close connection to broker nuk158.kr2.iwilab.com:9092.
[Sarama] 2014/06/24 16:56:04 kafka: broker: not connected
[Sarama] 2014/06/24 16:56:04 Registered new broker #3 at nuk158.kr2.iwilab.com:9092
[Sarama] 2014/06/24 16:56:04 Connected to broker nuk158.kr2.iwilab.com:9092
[Sarama] 2014/06/24 16:56:04 Failed to close connection to broker nuk158.kr2.iwilab.com:9092.
[Sarama] 2014/06/24 16:56:04 kafka: broker: not connected
[Sarama] 2014/06/24 16:56:04 Closed connection to broker nuk157.kr2.iwilab.com:9092
[Sarama] 2014/06/24 16:56:04 Start consuming partition 0...
[Sarama] 2014/06/24 16:56:04 Unexpected error processing FetchRequest; disconnecting broker nuk157.kr2.iwilab.com:9092: kafka: broker: not connected
[Sarama] 2014/06/24 16:56:04 Disconnecting Broker 2
[Sarama] 2014/06/24 16:56:04 Fetching metadata from broker nuk155.kr2.iwilab.com:9092
[Sarama] 2014/06/24 16:56:04 Failed to close connection to broker nuk157.kr2.iwilab.com:9092.
[Sarama] 2014/06/24 16:56:04 kafka: broker: not connected
[Sarama] 2014/06/24 16:56:04 Registered new broker #2 at nuk157.kr2.iwilab.com:9092
[Sarama] 2014/06/24 16:56:04 Connected to broker nuk157.kr2.iwilab.com:9092
[Sarama] 2014/06/24 16:56:05 Start consuming partition 1...
[Sarama] 2014/06/24 16:56:06 Start consuming partition 0...
```