{"action":"created","comment":{"url":"https://api.github.com/repos/apache/kafka/pulls/comments/80207158","id":80207158,"diff_hunk":"@@ -0,0 +1,220 @@\n+/**\n+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE\n+ * file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file\n+ * to You under the Apache License, Version 2.0 (the \"License\"); you may not use this file except in compliance with the\n+ * License. You may obtain a copy of the License at\n+ *\n+ * http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on\n+ * an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the\n+ * specific language governing permissions and limitations under the License.\n+ */\n+\n+package org.apache.kafka.streams.processor.internals;\n+\n+import org.apache.kafka.clients.ClientUtils;\n+import org.apache.kafka.clients.CommonClientConfigs;\n+import org.apache.kafka.clients.KafkaClient;\n+import org.apache.kafka.clients.NetworkClient;\n+import org.apache.kafka.clients.Metadata;\n+import org.apache.kafka.clients.ClientResponse;\n+import org.apache.kafka.clients.ClientRequest;\n+import org.apache.kafka.clients.consumer.ConsumerConfig;\n+import org.apache.kafka.clients.consumer.KafkaConsumer;\n+import org.apache.kafka.clients.producer.ProducerConfig;\n+import org.apache.kafka.common.Cluster;\n+import org.apache.kafka.common.Node;\n+import org.apache.kafka.common.PartitionInfo;\n+import org.apache.kafka.common.metrics.JmxReporter;\n+import org.apache.kafka.common.metrics.MetricConfig;\n+import org.apache.kafka.common.metrics.Metrics;\n+import org.apache.kafka.common.metrics.MetricsReporter;\n+import org.apache.kafka.common.network.ChannelBuilder;\n+import org.apache.kafka.common.network.Selector;\n+import org.apache.kafka.common.protocol.ApiKeys;\n+import org.apache.kafka.common.protocol.types.Struct;\n+import org.apache.kafka.common.requests.CreateTopicsRequest;\n+import org.apache.kafka.common.requests.CreateTopicsResponse;\n+import org.apache.kafka.common.requests.RequestSend;\n+import org.apache.kafka.common.requests.MetadataRequest;\n+import org.apache.kafka.common.requests.MetadataResponse;\n+import org.apache.kafka.common.serialization.Serdes;\n+import org.apache.kafka.common.utils.SystemTime;\n+import org.apache.kafka.common.utils.Time;\n+import org.apache.kafka.streams.StreamsConfig;\n+import org.apache.kafka.streams.errors.StreamsException;\n+import org.slf4j.Logger;\n+import org.slf4j.LoggerFactory;\n+\n+import java.net.InetSocketAddress;\n+import java.util.LinkedHashMap;\n+import java.util.List;\n+import java.util.Map;\n+import java.util.HashMap;\n+import java.util.Arrays;\n+import java.util.Properties;\n+import java.util.concurrent.TimeUnit;\n+\n+\n+public class StreamsKafkaClient {\n+\n+    private static final Logger log = LoggerFactory.getLogger(StreamsKafkaClient.class);\n+\n+    private KafkaClient kafkaClient;\n+    private StreamsConfig streamsConfig;\n+\n+    private static final int MAX_INFLIGHT_REQUESTS = 100;\n+    private static final long MAX_WAIT_TIME_MS = 30000;\n+\n+    public StreamsKafkaClient(final StreamsConfig streamsConfig) {\n+\n+        this.streamsConfig = streamsConfig;\n+        final Time time = new SystemTime();\n+\n+        final Map<String, String> metricTags = new LinkedHashMap<>();\n+        metricTags.put(\"client-id\", StreamsConfig.CLIENT_ID_CONFIG);\n+\n+        final Metadata metadata = new Metadata(streamsConfig.getLong(StreamsConfig.RETRY_BACKOFF_MS_CONFIG), streamsConfig.getLong(StreamsConfig.METADATA_MAX_AGE_CONFIG));\n+        final List<InetSocketAddress> addresses = ClientUtils.parseAndValidateAddresses(streamsConfig.getList(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG));\n+        metadata.update(Cluster.bootstrap(addresses), time.milliseconds());\n+\n+        final MetricConfig metricConfig = new MetricConfig().samples(streamsConfig.getInt(CommonClientConfigs.METRICS_NUM_SAMPLES_CONFIG))\n+                .timeWindow(streamsConfig.getLong(CommonClientConfigs.METRICS_SAMPLE_WINDOW_MS_CONFIG), TimeUnit.MILLISECONDS)\n+                .tags(metricTags);\n+        final List<MetricsReporter> reporters = streamsConfig.getConfiguredInstances(ProducerConfig.METRIC_REPORTER_CLASSES_CONFIG,\n+                MetricsReporter.class);\n+        // TODO: This should come from the KafkaStream\n+        reporters.add(new JmxReporter(\"kafka.streams\"));\n+        final Metrics metrics = new Metrics(metricConfig, reporters, time);\n+\n+        final ChannelBuilder channelBuilder = ClientUtils.createChannelBuilder(streamsConfig.values());\n+\n+        final Selector selector = new Selector(streamsConfig.getLong(StreamsConfig.CONNECTIONS_MAX_IDLE_MS_CONFIG), metrics, time, \"kafka-client\", channelBuilder);\n+\n+        kafkaClient = new NetworkClient(\n+                selector,\n+                metadata,\n+                streamsConfig.getString(StreamsConfig.CLIENT_ID_CONFIG),\n+                MAX_INFLIGHT_REQUESTS, // a fixed large enough value will suffice\n+                streamsConfig.getLong(StreamsConfig.RECONNECT_BACKOFF_MS_CONFIG),\n+                streamsConfig.getInt(StreamsConfig.SEND_BUFFER_CONFIG),\n+                streamsConfig.getInt(StreamsConfig.RECEIVE_BUFFER_CONFIG),\n+                streamsConfig.getInt(StreamsConfig.REQUEST_TIMEOUT_MS_CONFIG), time);\n+\n+    }\n+\n+\n+    /**\n+     * Cretes a new topic with the given number of partitions and replication factor.\n+     *\n+     * @param internalTopicConfig\n+     * @param numPartitions\n+     * @param replicationFactor\n+     */\n+    public void createTopic(final InternalTopicConfig internalTopicConfig, final int numPartitions, final int replicationFactor, final long windowChangeLogAdditionalRetention) {\n+        final Properties topicProperties = internalTopicConfig.toProperties(windowChangeLogAdditionalRetention);\n+        final Map<String, String> topicConfig = new HashMap<>();\n+        for (String key : topicProperties.stringPropertyNames()) {\n+            topicConfig.put(key, topicProperties.getProperty(key));\n+        }\n+        final CreateTopicsRequest.TopicDetails topicDetails = new CreateTopicsRequest.TopicDetails(numPartitions, (short) replicationFactor, topicConfig);\n+        final Map<String, CreateTopicsRequest.TopicDetails> topics = new HashMap<>();\n+        topics.put(internalTopicConfig.name(), topicDetails);\n+\n+        CreateTopicsRequest createTopicsRequest = new CreateTopicsRequest(topics, streamsConfig.getInt(StreamsConfig.REQUEST_TIMEOUT_MS_CONFIG));\n+\n+        ClientResponse clientResponse = sendRequest(createTopicsRequest.toStruct(), ApiKeys.CREATE_TOPICS);\n+        CreateTopicsResponse createTopicsResponse = new CreateTopicsResponse(clientResponse.responseBody());","path":"streams/src/main/java/org/apache/kafka/streams/processor/internals/StreamsKafkaClient.java","position":128,"original_position":128,"commit_id":"cb6891fe839cf6ca7ba46ca42437344764cf009e","original_commit_id":"cb6891fe839cf6ca7ba46ca42437344764cf009e","user":{"login":"dguy","id":54829,"avatar_url":"https://avatars.githubusercontent.com/u/54829?v=3","gravatar_id":"","url":"https://api.github.com/users/dguy","html_url":"https://github.com/dguy","followers_url":"https://api.github.com/users/dguy/followers","following_url":"https://api.github.com/users/dguy/following{/other_user}","gists_url":"https://api.github.com/users/dguy/gists{/gist_id}","starred_url":"https://api.github.com/users/dguy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dguy/subscriptions","organizations_url":"https://api.github.com/users/dguy/orgs","repos_url":"https://api.github.com/users/dguy/repos","events_url":"https://api.github.com/users/dguy/events{/privacy}","received_events_url":"https://api.github.com/users/dguy/received_events","type":"User","site_admin":false},"body":"`final`","created_at":"2016-09-23T09:06:30Z","updated_at":"2016-09-23T09:10:42Z","html_url":"https://github.com/apache/kafka/pull/1884#discussion_r80207158","pull_request_url":"https://api.github.com/repos/apache/kafka/pulls/1884","_links":{"self":{"href":"https://api.github.com/repos/apache/kafka/pulls/comments/80207158"},"html":{"href":"https://github.com/apache/kafka/pull/1884#discussion_r80207158"},"pull_request":{"href":"https://api.github.com/repos/apache/kafka/pulls/1884"}}},"pull_request":{"url":"https://api.github.com/repos/apache/kafka/pulls/1884","id":85892279,"html_url":"https://github.com/apache/kafka/pull/1884","diff_url":"https://github.com/apache/kafka/pull/1884.diff","patch_url":"https://github.com/apache/kafka/pull/1884.patch","issue_url":"https://api.github.com/repos/apache/kafka/issues/1884","number":1884,"state":"open","locked":false,"title":"KAFKA-4060: Remove zk client dependency in kafka streams","user":{"login":"hjafarpour","id":16784742,"avatar_url":"https://avatars.githubusercontent.com/u/16784742?v=3","gravatar_id":"","url":"https://api.github.com/users/hjafarpour","html_url":"https://github.com/hjafarpour","followers_url":"https://api.github.com/users/hjafarpour/followers","following_url":"https://api.github.com/users/hjafarpour/following{/other_user}","gists_url":"https://api.github.com/users/hjafarpour/gists{/gist_id}","starred_url":"https://api.github.com/users/hjafarpour/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hjafarpour/subscriptions","organizations_url":"https://api.github.com/users/hjafarpour/orgs","repos_url":"https://api.github.com/users/hjafarpour/repos","events_url":"https://api.github.com/users/hjafarpour/events{/privacy}","received_events_url":"https://api.github.com/users/hjafarpour/received_events","type":"User","site_admin":false},"body":"@dguy @guozhangwang This is a new PR for KAFKA-4060.","created_at":"2016-09-20T00:22:57Z","updated_at":"2016-09-23T09:10:42Z","closed_at":null,"merged_at":null,"merge_commit_sha":"94315e49ba0249ee107fc0d5e5ff3f4932f140b1","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/apache/kafka/pulls/1884/commits","review_comments_url":"https://api.github.com/repos/apache/kafka/pulls/1884/comments","review_comment_url":"https://api.github.com/repos/apache/kafka/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/kafka/issues/1884/comments","statuses_url":"https://api.github.com/repos/apache/kafka/statuses/cb6891fe839cf6ca7ba46ca42437344764cf009e","head":{"label":"hjafarpour:KAFKA-4060-Remove-ZkClient-dependency-in-Kafka-Streams-new","ref":"KAFKA-4060-Remove-ZkClient-dependency-in-Kafka-Streams-new","sha":"cb6891fe839cf6ca7ba46ca42437344764cf009e","user":{"login":"hjafarpour","id":16784742,"avatar_url":"https://avatars.githubusercontent.com/u/16784742?v=3","gravatar_id":"","url":"https://api.github.com/users/hjafarpour","html_url":"https://github.com/hjafarpour","followers_url":"https://api.github.com/users/hjafarpour/followers","following_url":"https://api.github.com/users/hjafarpour/following{/other_user}","gists_url":"https://api.github.com/users/hjafarpour/gists{/gist_id}","starred_url":"https://api.github.com/users/hjafarpour/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hjafarpour/subscriptions","organizations_url":"https://api.github.com/users/hjafarpour/orgs","repos_url":"https://api.github.com/users/hjafarpour/repos","events_url":"https://api.github.com/users/hjafarpour/events{/privacy}","received_events_url":"https://api.github.com/users/hjafarpour/received_events","type":"User","site_admin":false},"repo":{"id":65947010,"name":"kafka","full_name":"hjafarpour/kafka","owner":{"login":"hjafarpour","id":16784742,"avatar_url":"https://avatars.githubusercontent.com/u/16784742?v=3","gravatar_id":"","url":"https://api.github.com/users/hjafarpour","html_url":"https://github.com/hjafarpour","followers_url":"https://api.github.com/users/hjafarpour/followers","following_url":"https://api.github.com/users/hjafarpour/following{/other_user}","gists_url":"https://api.github.com/users/hjafarpour/gists{/gist_id}","starred_url":"https://api.github.com/users/hjafarpour/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hjafarpour/subscriptions","organizations_url":"https://api.github.com/users/hjafarpour/orgs","repos_url":"https://api.github.com/users/hjafarpour/repos","events_url":"https://api.github.com/users/hjafarpour/events{/privacy}","received_events_url":"https://api.github.com/users/hjafarpour/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/hjafarpour/kafka","description":"Mirror of Apache Kafka","fork":true,"url":"https://api.github.com/repos/hjafarpour/kafka","forks_url":"https://api.github.com/repos/hjafarpour/kafka/forks","keys_url":"https://api.github.com/repos/hjafarpour/kafka/keys{/key_id}","collaborators_url":"https://api.github.com/repos/hjafarpour/kafka/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/hjafarpour/kafka/teams","hooks_url":"https://api.github.com/repos/hjafarpour/kafka/hooks","issue_events_url":"https://api.github.com/repos/hjafarpour/kafka/issues/events{/number}","events_url":"https://api.github.com/repos/hjafarpour/kafka/events","assignees_url":"https://api.github.com/repos/hjafarpour/kafka/assignees{/user}","branches_url":"https://api.github.com/repos/hjafarpour/kafka/branches{/branch}","tags_url":"https://api.github.com/repos/hjafarpour/kafka/tags","blobs_url":"https://api.github.com/repos/hjafarpour/kafka/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/hjafarpour/kafka/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/hjafarpour/kafka/git/refs{/sha}","trees_url":"https://api.github.com/repos/hjafarpour/kafka/git/trees{/sha}","statuses_url":"https://api.github.com/repos/hjafarpour/kafka/statuses/{sha}","languages_url":"https://api.github.com/repos/hjafarpour/kafka/languages","stargazers_url":"https://api.github.com/repos/hjafarpour/kafka/stargazers","contributors_url":"https://api.github.com/repos/hjafarpour/kafka/contributors","subscribers_url":"https://api.github.com/repos/hjafarpour/kafka/subscribers","subscription_url":"https://api.github.com/repos/hjafarpour/kafka/subscription","commits_url":"https://api.github.com/repos/hjafarpour/kafka/commits{/sha}","git_commits_url":"https://api.github.com/repos/hjafarpour/kafka/git/commits{/sha}","comments_url":"https://api.github.com/repos/hjafarpour/kafka/comments{/number}","issue_comment_url":"https://api.github.com/repos/hjafarpour/kafka/issues/comments{/number}","contents_url":"https://api.github.com/repos/hjafarpour/kafka/contents/{+path}","compare_url":"https://api.github.com/repos/hjafarpour/kafka/compare/{base}...{head}","merges_url":"https://api.github.com/repos/hjafarpour/kafka/merges","archive_url":"https://api.github.com/repos/hjafarpour/kafka/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/hjafarpour/kafka/downloads","issues_url":"https://api.github.com/repos/hjafarpour/kafka/issues{/number}","pulls_url":"https://api.github.com/repos/hjafarpour/kafka/pulls{/number}","milestones_url":"https://api.github.com/repos/hjafarpour/kafka/milestones{/number}","notifications_url":"https://api.github.com/repos/hjafarpour/kafka/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/hjafarpour/kafka/labels{/name}","releases_url":"https://api.github.com/repos/hjafarpour/kafka/releases{/id}","deployments_url":"https://api.github.com/repos/hjafarpour/kafka/deployments","created_at":"2016-08-17T22:39:02Z","updated_at":"2016-08-17T22:39:07Z","pushed_at":"2016-09-22T17:13:26Z","git_url":"git://github.com/hjafarpour/kafka.git","ssh_url":"git@github.com:hjafarpour/kafka.git","clone_url":"https://github.com/hjafarpour/kafka.git","svn_url":"https://github.com/hjafarpour/kafka","homepage":null,"size":33970,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"trunk"}},"base":{"label":"apache:trunk","ref":"trunk","sha":"a632716a3c9a871f325c6f13aefa9aed0add4b82","user":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"repo":{"id":2211243,"name":"kafka","full_name":"apache/kafka","owner":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apache/kafka","description":"Mirror of Apache Kafka","fork":false,"url":"https://api.github.com/repos/apache/kafka","forks_url":"https://api.github.com/repos/apache/kafka/forks","keys_url":"https://api.github.com/repos/apache/kafka/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/kafka/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/kafka/teams","hooks_url":"https://api.github.com/repos/apache/kafka/hooks","issue_events_url":"https://api.github.com/repos/apache/kafka/issues/events{/number}","events_url":"https://api.github.com/repos/apache/kafka/events","assignees_url":"https://api.github.com/repos/apache/kafka/assignees{/user}","branches_url":"https://api.github.com/repos/apache/kafka/branches{/branch}","tags_url":"https://api.github.com/repos/apache/kafka/tags","blobs_url":"https://api.github.com/repos/apache/kafka/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/kafka/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/kafka/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/kafka/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/kafka/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/kafka/languages","stargazers_url":"https://api.github.com/repos/apache/kafka/stargazers","contributors_url":"https://api.github.com/repos/apache/kafka/contributors","subscribers_url":"https://api.github.com/repos/apache/kafka/subscribers","subscription_url":"https://api.github.com/repos/apache/kafka/subscription","commits_url":"https://api.github.com/repos/apache/kafka/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/kafka/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/kafka/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/kafka/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/kafka/contents/{+path}","compare_url":"https://api.github.com/repos/apache/kafka/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/kafka/merges","archive_url":"https://api.github.com/repos/apache/kafka/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/kafka/downloads","issues_url":"https://api.github.com/repos/apache/kafka/issues{/number}","pulls_url":"https://api.github.com/repos/apache/kafka/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/kafka/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/kafka/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/kafka/labels{/name}","releases_url":"https://api.github.com/repos/apache/kafka/releases{/id}","deployments_url":"https://api.github.com/repos/apache/kafka/deployments","created_at":"2011-08-15T18:06:16Z","updated_at":"2016-09-23T06:11:14Z","pushed_at":"2016-09-23T07:05:49Z","git_url":"git://github.com/apache/kafka.git","ssh_url":"git@github.com:apache/kafka.git","clone_url":"https://github.com/apache/kafka.git","svn_url":"https://github.com/apache/kafka","homepage":null,"size":49370,"stargazers_count":3810,"watchers_count":3810,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":2364,"mirror_url":"git://git.apache.org/kafka.git","open_issues_count":252,"forks":2364,"open_issues":252,"watchers":3810,"default_branch":"trunk"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/kafka/pulls/1884"},"html":{"href":"https://github.com/apache/kafka/pull/1884"},"issue":{"href":"https://api.github.com/repos/apache/kafka/issues/1884"},"comments":{"href":"https://api.github.com/repos/apache/kafka/issues/1884/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/kafka/pulls/1884/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/kafka/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/kafka/pulls/1884/commits"},"statuses":{"href":"https://api.github.com/repos/apache/kafka/statuses/cb6891fe839cf6ca7ba46ca42437344764cf009e"}}}}
{"actor":{"display_login":"dguy"}}