/*******************************************************************************
 * Copyright 2013 Renjie Yao
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/
package org.apache.flume.source.kafka;

import java.io.IOException;
import java.util.Map;
import java.util.Properties;

import kafka.consumer.Consumer;
import kafka.consumer.ConsumerConfig;
import kafka.javaapi.consumer.ConsumerConnector;

import org.apache.flume.Context;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public class KafkaSourceUtil {
	private static final Logger log = LoggerFactory.getLogger(KafkaSourceUtil.class);

	public static Properties getKafkaConfigProperties(Context context) {
		log.info("context={}",context.toString());
		Properties props = new Properties();
		Map<String, String> contextMap = context.getParameters();
		for(String key : contextMap.keySet()) {
			if (!key.equals("type") && !key.equals("channel")) {
				props.setProperty(key, context.getString(key));
				log.info("key={},value={}",key,context.getString(key));
			}
		}
		return props;
	}
	public static ConsumerConnector getConsumer(Context context) throws IOException, InterruptedException {
		ConsumerConfig consumerConfig = new ConsumerConfig(getKafkaConfigProperties(context));
		ConsumerConnector consumer = Consumer.createJavaConsumerConnector(consumerConfig);
		return consumer;
	}
}



















@@ -81,49 +81,259 @@
 %0A * 
-Copyright 2013 Renjie Yao%0A * %0A * Licensed
+Licensed to the Apache Software Foundation (ASF) under one%0A * or more contributor license agreements.  See the NOTICE file%0A * distributed with this work for additional information%0A * regarding copyright ownership.  The ASF licenses this file%0A * to you
  und
@@ -371,16 +371,19 @@
 2.0 (the
+%0A *
  %22Licens
@@ -386,19 +386,16 @@
 cense%22);
-%0A *
  you may
@@ -433,16 +433,19 @@
 mpliance
+%0A *
  with th
@@ -454,19 +454,17 @@
 License.
-%0A *
+ 
  You may
@@ -503,13 +503,12 @@
 %0A * 
+ 
 %0A *
-  
  htt
@@ -550,16 +550,17 @@
 -2.0%0A * 
+ 
 %0A * Unle
@@ -613,16 +613,19 @@
 writing,
+%0A *
  softwar
@@ -625,19 +625,16 @@
 software
-%0A *
  distrib
@@ -676,16 +676,19 @@
 ed on an
+%0A *
  %22AS IS%22
@@ -694,19 +694,16 @@
 %22 BASIS,
-%0A *
  WITHOUT
@@ -734,16 +734,19 @@
 S OF ANY
+%0A *
  KIND, e
@@ -770,19 +770,17 @@
 implied.
-%0A *
+ 
  See the
@@ -795,16 +795,19 @@
  for the
+%0A *
  specifi
@@ -842,19 +842,16 @@
 ions and
-%0A *
  limitat
@@ -854,16 +854,19 @@
 itations
+%0A *
  under t
@@ -878,16 +878,17 @@
 cense.%0A 
+*
 ********

add copyright