设为首页 收藏本站
查看: 1302|回复: 0

[经验分享] Apache Kafka

[复制链接]

尚未签到

发表于 2017-12-25 13:38:06 | 显示全部楼层 |阅读模式
  关于我们为什么需要Schema Registry?
  参考,
  https://www.confluent.io/blog/how-i-learned-to-stop-worrying-and-love-the-schema-part-1/
  https://www.confluent.io/blog/schema-registry-kafka-stream-processing-yes-virginia-you-really-need-one/
  https://www.confluent.io/blog/stream-data-platform-2/
  
  Use Avro as Your Data Format
  We think Avro is the best choice for a number of reasons:
  

  • It has a direct mapping to and from JSON   
  • It has a very compact format. The bulk of JSON, repeating every field name with every single record, is what makes JSON inefficient for high-volume usage.   
  • It is very fast.   
  • It has great bindings for a wide variety of programming languages so you can generate Java objects that make working with event data easier, but it does not require code generation so tools can be written generically for any data stream.   
  • It has a rich, extensible schema language defined in pure JSON   
  • It has the best notion of compatibility for evolving your data over time.
  One of the critical features of Avro is the ability to define a schema for your data. For example an event that represents the sale of a product might look like this:
{  
"time": 1424849130111,
  
"customer_id": 1234,
  
"product_id": 5678,
  
"quantity":3,
  
"payment_type": "mastercard"
  
}
  

  

  It might have a schema like this that defines these five fields:
  

  

{  
"type": "record",
  
"doc":"This event records the sale of a product",
  
"name": "ProductSaleEvent",
  
"fields" : [
  
{"name":"time", "type":"long", "doc":"The time of the purchase"},
  
{"name":"customer_id", "type":"long", "doc":"The customer"},
  
{"name":"product_id", "type":"long", "doc":"The product"},
  
{"name":"quantity", "type":"int"},
  
{"name":"payment",
  
"type":{"type":"enum",
  
"name":"payment_types",
  
"symbols":["cash","mastercard","visa"]},
  
"doc":"The method of payment"}
  
]
  
}
  

  


  Here is how these schemas will be put to use. You will associate a schema like this with each Kafka topic. You can think of the schema much like the schema of a>  The schemas end up serving a number of critical purposes:


  • They let the producers or consumers of data streams know the right fields are need in an event and what type each field is.
  • They document the usage of the event and the meaning of each field in the “doc” fields.
  • They protect downstream data consumers from malformed data, as only valid data will be permitted in the topic.

The Need For Schemas
  Robustness
  One of the primary advantages of this type of architecture where data is modeled as streams is that applications are decoupled.
  Clarity and Semantics
  Worse, the actual meaning of the data becomes obscure and often misunderstood by different applications because there is no real canonical documentation for the meaning of the fields. One person interprets a field one way and populates it accordingly and another interprets it differently.
  Compatibility
  Schemas also help solve one of the hardest problems in organization-wide data flow: modeling and handling change in data format. Schema definitions just capture a point in time, but your data needs to evolve with your business and with your code.
  Schemas give a mechanism for reasoning about which format changes will be compatible and (hence won’t require reprocessing) and which won’t.
  Schemas are a Conversation
  However data streams are different; they are a broadcast channel. Unlike an application’s database, the writer of the data is, almost by definition, not the reader. And worse, there are many readers, often in different parts of the organization. These two groups of people, the writers and the readers, need a concrete way to describe the data that will be exchanged between them and schemas provide exactly this.
  Schemas Eliminate The Manual Labor of Data Science
  It is almost a truism that data science, which I am using as a short-hand here for “putting data to effective use”, is 80% parsing, validation, and low-level data munging.

KIP-69 - Kafka Schema Registry
  pending状态,这个KIP估计会被cancel掉
  因为confluent.inc已经提供相应的方案,
  https://github.com/confluentinc/schema-registry
  http://docs.confluent.io/3.0.1/schema-registry/docs/index.html
  比较牛逼的是,有人为这个开发了UI,
  https://www.landoop.com/blog/2016/08/schema-registry-ui/
  本身使用,都是通过http进行Schema的读写,比较简单
  设计,
  参考, http://docs.confluent.io/3.0.1/schema-registry/docs/design.html
DSC0000.png

  主备架构,通过zk来选主
  每个schema需要一个唯一id,这个id也通过zk来保证递增
  schema存在kafka的一个特殊的topic中,_schemas,一个单partition的topic
  我的理解,在注册和查询schema的时候,是通过local caches进行检索的,kafka的topic可以用于replay来重建caches

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-427840-1-1.html 上篇帖子: Apache Kafka系列(二) 命令行工具(CLI) 下篇帖子: Apache Samza流处理框架介绍——kafka+LevelDB的Key/Value数据库来存储历史消息+?
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表