kafka的configuration
1 import java.io.Serializable; 2 import java.util.Map; 3 import java.util.Map.Entry; 4 import java.util.Properties; 5 6 /** 7 * <p> 8 * Kafka配置类 9 * </p> 10 * 11 * @author 12 * @version V1.0 13 * @modify by user: $author$ $date$ 14 * @modify by reason: {方法名}:{原因} 15 */ 16 public class Configuration implements Serializable{ 17 /** 18 * 序列化ID 19 */ 20 private static final long serialVersionUID = 1L; 21 22 public final static String PRODUCER_TYPE = "producer.type"; 23 public final static String SERIALIZER_CLASS = "serializer.class"; 24 public final static String BOOTSTRAP_SERVERS = "bootstrap.servers"; 25 public final static String ZOOKEEPER_CONNECT = "zookeeper.connect"; 26 public final static String GROUP_ID = "group.id"; 27 public final static String ZOOKEEPER_SYNC_TIME_MS = "zookeeper.sync.time.ms"; 28 public final static String ZOOKEEPER_SESSION_TIMEOUT_MS = "zookeeper.session.timeout.ms"; 29 public final static String AUTO_COMMIT_ENABLE = "auto.commit.enable"; 30 public final static String AUTO_COMMIT_INTERVAL_MS = "auto.commit.interval.ms"; 31 public final static String FETCH_MESSAGE_MAX_BYTES = "fetch.message.max.bytes"; 32 public final static String BATCH_SIZE = "batch.size"; 33 public final static String SUBMIT_TIMEOUT = "submit.timeout"; 34 public final static String AUTO_OFFSET_RESET = "auto.offset.reset"; 35 public final static String REQUEST_REQUIRED_ACKS = "request.required.acks"; 36 37 public static final String MAX_REQUEST_SIZE = "max.request.size"; 38 public static final String COSUMER_KEY = "cosumer.key"; 39 40 private Properties _properties; 41 42 /** 43 * 创建一个新的实例Configuration. 44 */ 45 public Configuration() { 46 _properties = new Properties(); 47 } 48 49 /** 50 * 创建一个新的实例Configuration. 51 * 52 * @param properties 53 */ 54 public Configuration(Map<String, String> properties) { 55 _properties = new Properties(); 56 for (Entry<String, String> entry : properties.entrySet()) { 57 _properties.put(entry.getKey(), entry.getValue()); 58 } 59 } 60 61 /** 62 * 创建一个新的实例Configuration. 63 * 64 * @param properties 65 */ 66 public Configuration(Properties properties) { 67 _properties = properties; 68 } 69 70 /** 71 * 添加配置信息 72 * 73 * @author zhuchao 2015年7月6日 上午9:48:04 74 * @param key 75 * @param value 76 */ 77 public void addProperty(String key, String value) { 78 _properties.put(key, value); 79 } 80 81 /** 82 * 获取所有配置信息 83 * 84 * @author zhuchao 2015年7月6日 上午9:47:47 85 * @return 86 */ 87 public Properties getConfig() { 88 return _properties; 89 } 90 91 /** 92 * 根据key获取配置信息 93 * 94 * @author zhuchao 2015年7月6日 上午9:47:26 95 * @param key 96 * @return 97 */ 98 public String getProperty(String key) { 99 return (_properties.get(key) != null) ? (String) _properties.get(key) : null; 100 } 101 }