introduce-kafka
来源:互联网 发布:lol网络不稳定断开连接 编辑:程序博客网 时间:2024/06/11 14:12
介绍:
a high-throughput distributed messaging system.
基本模型
模型组成元素
- Kafka maintains feeds of messages in categories called topics.
- We’ll call processes that publish messages to a Kafka topic producers.
- We’ll call processes that subscribe to topics and process the feed of published messages consumers..
- Kafka is run as a cluster comprised of one or more servers each of which is called a broker.
partition
Kafka does it better. By having a notion of parallelism—the partition—within the topics, Kafka is able to provide both ordering guarantees and load balancing over a pool of consumer processes. This is achieved by assigning the partitions in the topic to the consumers in the consumer group so that each partition is consumed by exactly one consumer in the group. By doing this we ensure that the consumer is the only reader of that partition and consumes the data in order. Since there are many partitions this still balances the load over many consumer instances. Note however that there cannot be more consumer instances than partitions.
Kafka only provides a total order over messages within a partition, not between different partitions in a topic. Per-partition ordering combined with the ability to partition data by key is sufficient for most applications. However, if you require a total order over messages this can be achieved with a topic that has only one partition, though this will mean only one consumer process.
producer
$message相当于key,kafka会对\$message进行平衡处理,分配到partition上。
指定的两个参数,一个是key, 一个是topic
<?php$host = '';$port = '';$topic = 'test';$producer = new Kafka_Producer($host, $port, $topic);$message = fopen('php://stdin', 'r');$byte = $producer->send($message, $topic);?>
Consumer
pull模式,从服务器拿消息来进行处理。
拿消息的时候参数指定了:topic , partition, offset,可以看出,消息在partition存放的模式。
$host = '';$port = '';$topic = 'test';$maxSize = 1000;$sockTimeout = 5;$offset = 0;$partition = 0;$consumer = new Kafka_SimpleConsumer($host, $port, $sockTimeout, $maxSize);$fetchRequest = new Kafka_FetchRequest($topic, $partition, $offset, $maxSize);$partialOffset = 0;$message = $consumer->fetch($fetchRequest);
参考的博客地址:
http://www.cnblogs.com/metoy/p/4452124.html
http://www.tuicool.com/articles/zIzyq2#0-tsina-1-48639-397232819ff9a47a7b7e80a40613cfe1
- introduce-kafka
- introduce
- Introduce
- introduce
- SpringFrameWork Introduce
- Introduce IOC
- Introduce VC
- Introduce Clearcase
- iaSolution Introduce
- Introduce RESTful
- Introduce yourself
- drawRect introduce
- Introduce myself
- 按键精灵Introduce
- Introduce yourself
- introduce myself
- english introduce
- HOOPS INTRODUCE
- “==”和equals方法区别
- QQ安装教程 -for wuqs
- OC_SingleTon(单例)
- HTTPie: a CLI, cURL-like tool for humans
- Frame可视化调用的顺序问题
- introduce-kafka
- 记一次服务器被恶意攻击的情况
- 华为OJ 名字漂亮度
- linux设置dhcp中继代理
- Android view利用canvas绘制动画(一)
- 【1】依照Django官网,编写一个web app 创建工程/配置数据库
- Android 开源项目分类汇总
- JStorm中消息确保处理机制
- Spring3.0+Struts2.2+Hibernate3.6整合与常见问题