http://www.aboutyun.com/thread-9906-1-1.html

http://my.oschina.net/u/591402/blog/152837

https://github.com/bkimminich/apache-kafka-book-examples/blob/master/src/test/kafka/SimplePartitioner.java

https://cwiki.apache.org/confluence/display/KAFKA/0.8.0+Producer+Example

http://stackoverflow.com/questions/18202986/kafka-partitioner-class-assign-message-to-partition-within-topic-using-key

kafka分片类正确的写法如下:

package com.*.epp.kafka;

import java.util.Random;

import kafka.producer.Partitioner;
import kafka.utils.VerifiableProperties; public class CustomPartition implements Partitioner, scala.ScalaObject { public CustomPartition(VerifiableProperties props) { } /*
* (non-Javadoc)
* @see kafka.producer.Partitioner#partition(java.lang.Object, int)
*/
@Override
public int partition(Object key, int numPartitions) {
if (key == null) {
Random random = new Random();
return random.nextInt(numPartitions);
} else {
int result = Math.abs(key.hashCode()) % numPartitions;
return result;
}
} }

producer怎样发送消息到指定的partitions的更多相关文章

  1. [转] C#中发送消息给指定的窗口,以及接收消息

    原文C#中发送消息给指定的窗口,以及接收消息 public class Note { //声明 API 函数 [DllImport("User32.dll", EntryPoint ...

  2. kafka producer batch 发送消息

    1. 使用 KafkaProducer 发送消息,是按 batch 发送的,producer 首先把消息放入 ProducerBatch 中: org.apache.kafka.clients.pro ...

  3. ActiveMQ producer不断发送消息,会导致broker内存耗尽吗?

    http://activemq.apache.org/my-producer-blocks.html 回答了这个问题: ActiveMQ 5.x 支持Message Cursors,它默认把消息从内存 ...

  4. 【转载】Delphi7从子线程中发送消息到主线程触发事件执行

    在对数据库的操作时,有时要用一个子线程来进行后台的数据操作.比如说数据备份,转档什么的.在主窗口还能同是进行其它操作.而有时后台每处理一个数据文件,要向主窗口发送消息,让主窗口实时显示处理进度在窗口上 ...

  5. Kafka学习笔记(6)----Kafka使用Producer发送消息

    1. Kafka的Producer 不论将kafka作为什么样的用途,都少不了的向Broker发送数据或接受数据,Producer就是用于向Kafka发送数据.如下: 2. 添加依赖 pom.xml文 ...

  6. Linux给指定用户或全部用户(已登录)发送消息

    在局域网络内很多时候是许多人共用一些机器,但如果多个人同时在使用同一台机器必定会发生一些冲突,比如系统的某些配置被修改,这样引起一些麻烦.那么如果在使用该机器之前,先给登录到该机器的所有其他用户发送一 ...

  7. kafka producer 发送消息简介

    kafka 的 topic 由 partition 组成,producer 会根据 key,选择一个 partition 发送消息,而 partition 有多个副本,副本有 leader 和 fol ...

  8. ActiveMQ producer同步/异步发送消息

    http://activemq.apache.org/async-sends.html producer发送消息有同步和异步两种模式,可以通过代码配置: ((ActiveMQConnection)co ...

  9. java集成WebSocket向指定用户发送消息

    一.WebSocket简单介绍 随着互联网的发展,传统的HTTP协议已经很难满足Web应用日益复杂的需求了.近年来,随着HTML5的诞生,WebSocket协议被提出,它实现了浏览器与服务器的全双工通 ...

随机推荐

  1. Two-phase Termination模式

    停止线程是一个目标简单而实现却不那么简单的任务.首先,Java没有提供直接的API用于停止线程.此外,停止线程时还有一些额外的细节需要考虑,如待停止的线程处于阻塞(等待锁)或者等待状态(等待其它线程) ...

  2. Sed&awk笔记之awk篇

    http://blog.csdn.net/a81895898/article/details/8482333 Awk是什么 Awk.sed与grep,俗称Linux下的三剑客,它们之间有很多相似点,但 ...

  3. 【HDU2825】Wireless Password (AC自动机+状压DP)

    Wireless Password Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %I64d & %I64u De ...

  4. 精确到时分秒的jQuery插件例子

    demo.html: <!DOCTYPE html> <html> <head>  <meta http-equiv="Content-Type&q ...

  5. BZOJ3036: 绿豆蛙的归宿&Wikioi2488:绿豆蛙的归宿

    3036: 绿豆蛙的归宿 Time Limit: 2 Sec  Memory Limit: 128 MBSubmit: 108  Solved: 73[Submit][Status] Descript ...

  6. ORACLE软件下载地址

    Oracle Database 11g Release 2 Standard Edition and Enterprise Edition Software Downloads Oracle 数据库 ...

  7. window.alert弹出处理

    # -*- coding:utf-8 -*- """ window.alert 处理 """ from selenium import we ...

  8. UVa11090 Going in Cycle!!

    UVa11090 Going in Cycle!! 链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=34650 [思路] ...

  9. SRM 440(1-250pt, 1-500pt)

    DIV1 250pt 题意:小球从一段折线斜坡上滚下来,告诉所用时间,求重力加速度. 解法:二分答案模拟即可. tag:二分,simulation // BEGIN CUT HERE /* * Aut ...

  10. Scrapinghub | Professional Services

    VShell破解版 VShell破解版 Scrapinghub | Professional Services OUR PROFESSIONAL SERVICES INCLUDE