kafka 0.10.0.0 released

 

Interceptors的概念应该来自flume

参考,http://blog.csdn.net/xiao_jun_0820/article/details/38111305

比如,flume提供的

Timestamp Interceptor

Host Interceptor

Static Interceptor

Regex Filtering Interceptor

Regex Extractor Interceptor

可以对于流过的message进行一些包装,比如插入时间,host,或做些过滤等etl操作

 

所以kafka在producer和consumer端也都提供这样的Interceptors接口,

 

ProducerInterceptor

/**
* A plugin interface to allow things to intercept events happening to a producer record,
* such as sending producer record or getting an acknowledgement when a record gets published
*/
public interface ProducerInterceptor<K, V> extends Configurable {
/**
* This is called when client sends record to KafkaProducer, before key and value gets serialized.
* @param record the record from client
* @return record that is either original record passed to this method or new record with modified key and value.
*/
public ProducerRecord<K, V> onSend(ProducerRecord<K, V> record); /**
* This is called when the send has been acknowledged
* @param metadata The metadata for the record that was sent (i.e. the partition and offset). The metadata information may be only partially filled, if an error occurred. Topic will be always set, and if partition is not -1, partition will be set partition set/assigned to this record.
* @param exception The exception thrown during processing of this record. Null if no error occurred.
*/
public void onAcknowledgement(RecordMetadata metadata, Exception exception); /**
* This is called when interceptor is closed
*/
public void close();
}

onSend() will be called in KafkaProducer.send(), before key and value gets serialized and before partition gets assigned.

If the implementation modifies key and/or value, it must return modified key and value in a new ProducerRecord object.

onAcknowledgement() will be called when the send is acknowledged. It has same API as Callback.onCompletion(), and is called just before Callback.onCompletion() is called.

多个multiple interceptors之间是可以串联的

ProducerInterceptor APIs will be called from multiple threads: onSend() will be called on submitting thread and onAcknowledgement() will be called on producer I/O thread.

 

ConsumerInterceptor

/**
* A plugin interface to allow things to intercept Consumer events such as receiving a record or record being consumed
* by a client.
*/
public interface ConsumerInterceptor<K, V> extends Configurable {
/**
* This is called when the records are about to be returned to the client.
* @param records records to be consumed by the client. Null if record dropped/ignored/discarded (non consumable)
* @return records that is either original 'records' passed to this method or modified set of records
*/
public ConsumerRecords<K, V> onConsume(ConsumerRecords<K, V> records); /**
* This is called when offsets get committed
* This method will be called when the commit request sent to the server has been acknowledged.
* @param offsets A map of the offsets and associated metadata that this callback applies to
*/
public void onCommit(Map<TopicPartition, OffsetAndMetadata> offsets); /**
* This is called when interceptor is closed
*/
public void close();
}

onConsume() will be called in KafkaConsumer.poll(), just before poll() returns ConsumerRecords.

onCommit() will be called when offsets get committed: just before OffsetCommitCallback.onCompletion() is called and in ConsumerCoordinator.commitOffsetsSync() on successful commit.

Since new consumer is single-threaded, ConsumerInterceptor API will be called from a single thread.

 

总结,

Interceptor作为一种plugin可以做些,对message的decorate或cleaning或filtering等一些轻量的工作,最主要的用途还是用于监控,trace message

Interceptor可以串联执行

Interceptor必须要轻量,因为如果耗时就会影响链路的throughput

 

confluent公司也提供相应的interceptor产品,用于data stream的监控

http://docs.confluent.io/3.0.0/control-center/docs/clients.html

 

同时,为了更好的监控和audit

Currently, RecordMetadata contains topic/partition, offset, and timestamp (KIP-32).

We propose to add remaining record's metadata in RecordMetadata: checksum and record size. Both checksum and record size are useful for monitoring and audit.

For symmetry, we also propose to expose the same metadata on consumer side and make available to interceptors.

We will add checksum and record size fields to RecordMetadata and ConsumerRecord.

public final class RecordMetadata {

private final long offset;

private final TopicPartition topicPartition;

private final long checksum;                <<== NEW: checksum of the record

private final int size;                     <<== NEW: record size in bytes(before compression)

 

public final class ConsumerRecord<K, V> {

.......

private final long checksum;               <<== NEW: checksum of the record

private final int size;                    <<== NEW: record size in bytes (after decompression)

Apache Kafka - KIP-42: Add Producer and Consumer Interceptors的更多相关文章

  1. 如何创建Kafka客户端:Avro Producer和Consumer Client

    1.目标 - Kafka客户端 在本文的Kafka客户端中,我们将学习如何使用Kafka API 创建Apache Kafka客户端.有几种方法可以创建Kafka客户端,例如最多一次,至少一次,以及一 ...

  2. 漫游Kafka设计篇之Producer和Consumer

    Kafka Producer 消息发送 producer直接将数据发送到broker的leader(主节点),不需要在多个节点进行分发.为了帮助producer做到这点,所有的Kafka节点都可以及时 ...

  3. 漫游Kafka设计篇之Producer和Consumer(4)

    Kafka Producer 消息发送 producer直接将数据发送到broker的leader(主节点),不需要在多个节点进行分发.为了帮助producer做到这点,所有的Kafka节点都可以及时 ...

  4. apache kafka源码分析-Producer分析---转载

    原文地址:http://www.aboutyun.com/thread-9938-1-1.html 问题导读1.Kafka提供了Producer类作为java producer的api,此类有几种发送 ...

  5. Apache Kafka – KIP 32,33 Time Index

    32, 33都是和时间相关的, KIP-32 - Add timestamps to Kafka message 引入版本,0.10.0.0 需要给kafka的message加上时间戳,这样更方便一些 ...

  6. Apache Kafka Producer For Beginners

    在我们上一篇Kafka教程中,我们讨论了Kafka Cluster.今天,我们将通过示例讨论Kafka Producer.此外,我们将看到KafkaProducer API和Producer API. ...

  7. 实践部署与使用apache kafka框架技术博文资料汇总

    前一篇Kafka框架设计来自英文原文(Kafka Architecture Design)的翻译及整理文章,非常有借鉴性,本文是从一个企业使用Kafka框架的角度来记录及整理的Kafka框架的技术资料 ...

  8. Apache Kafka: Next Generation Distributed Messaging System---reference

    Introduction Apache Kafka is a distributed publish-subscribe messaging system. It was originally dev ...

  9. 【Apache Kafka】二、Kafka安装及简单示例

    (一)Apache Kafka安装 1.安装环境与前提条件   安装环境:Ubuntu16.04   前提条件: ubuntu系统下安装好jdk 1.8以上版本,正确配置环境变量 ubuntu系统下安 ...

随机推荐

  1. 基于mindwave脑电波进行疲劳检测算法的设计(1)

    一.简介 脑波,又称之为脑电波,是人大脑发出的电波,非常的微弱,只能通过设备来检测.人的脑波在不同状态下,会不同,因此可以通过脑波来量化分析人的精神状态. 科学家讲脑电波分为四种,以下为详细解释 (1 ...

  2. Fluent动网格【7】:网格节点运动

    在动网格中,对于那些既包含了运动也包含了变形的区域,可以通过UDF来指定区域中每一个节点的位置.这给了用户最大的自由度来指定网格的运动.在其他的动网格技术中(如重叠网格)则很难做到这一点.定义网格节点 ...

  3. java InputStream和OutputStream

    InputStream类型 类 功能 构造器参数 如何使用 ByteArrayInputStream 允许将内存的缓冲区当做InputStreams使用 缓冲区,字节将从中取出 作为一种数据源:将其与 ...

  4. js中如何把字符串转化为对象、数组示例代码

    很明显是一个对象,但如何把文本转为对象呢.使用eval();注意一定要加括号,否则会转换失败 把文本转化为对象 var test='{ colkey: "col", colsinf ...

  5. Java知多少(38)抽象类的概念和使用

    在自上而下的继承层次结构中,位于上层的类更具有通用性,甚至可能更加抽象.从某种角度看,祖先类更加通用,它只包含一些最基本的成员,人们只将它作为派生其他类的基类,而不会用来创建对象.甚至,你可以只给出方 ...

  6. prototype [ˈprəʊtətaɪp] 原型

    <script> Array.prototype.mysort = function(){ let s = this; for(i=0;i<s.length;i++){ s[i] = ...

  7. shell脚本中的逻辑判断 文件目录属性判断 if特殊用法 case判断

    case判断 • 格式 case  变量名 in                       value1)                           command            ...

  8. Android DiskLruCache完全解析,硬盘缓存的最佳方案(转)

    概述 记得在很早之前,我有写过一篇文章<Android高效加载大图.多图解决方案,有效避免程序OOM>,这篇文章是翻译自Android Doc的,其中防止多图OOM的核心解决思路就是使用L ...

  9. firadisk 把 win7(32位) 装入 VHD :仅仅支持内存模式:--mem

    关键1:对于 win7(32位)来说,还可以在设备管理器内,通过添加“过时”硬件的方式导入wvblk驱动. 附件: grub4dos firadisk驱动

  10. gradle教程 [原创](eclipse/ADT下 非插件 非Android Studio/AS)纯手打 第二篇:gradle简单实战

    一个bug 一个脚印的叫你们用gradle. 1介于网络上的很多资料都是老的 不适用与现在的新版本gradle 尤其是有些gradle方法改名了老的用不了 2介于网上都是粘贴复制并且零碎我很蛋疼啊,走 ...