Zeppelin 自定义Kafka解释器Interpreter开发
自定义解释器开发步骤见下文:
这里主要介绍自定义的Interpreter类:
一. 生产者解释器 KafkaProducerInterpreter:
public class KafkaProducerInterpreter extends Interpreter {
private KafkaProducer kafkaProducer;
private Logger logger = LoggerFactory.getLogger(KafkaProducerInterpreter.class);
public KafkaProducerInterpreter(Properties property) {
super(property);
}
public void open() {
//Producer 配置
Properties producerProp = new Properties();
producerProp.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG,getProperty("bootstrap.servers"));
//每当多个记录被发送到同一个分区时,生产者将尝试将记录批处理更少-16M
producerProp.put(ProducerConfig.BATCH_SIZE_CONFIG,getProperty("batch.size"));
//生产者将在请求传输之间到达的任何记录组合成一个批量请求的时间
producerProp.put(ProducerConfig.LINGER_MS_CONFIG,getProperty("linger.ms"));
//生产者可以用来缓冲等待发送到服务器的记录的总字节数-32M
producerProp.put(ProducerConfig.BUFFER_MEMORY_CONFIG,getProperty("buffer.memory"));
producerProp.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG,getProperty("key.serializer"));
producerProp.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG,getProperty("value.serializer"));
kafkaProducer = new KafkaProducer<String, String>(producerProp);
}
public void close() {
}
public InterpreterResult interpret(String cmd, InterpreterContext interpreterContext) {
//消息格式