0
在我的測試程序中,我開始收聽。然後在循環中發送消息。 如果我發送一條消息,它不列出該消息。如果我發送2條消息,它將監聽一條消息。如果我發送3條消息,它會收聽2條消息。爲什麼?爲什麼卡夫卡消費者不聽第一條消息?
生產者
KeyedMessage<String, byte[]> message = new KeyedMessage<String, byte[]>(topic, serializedBytes);
if (log.isDebugEnabled()) {
log.debug("producing messages to topic : " + topic + "file : " + payload.get("name"));
}
for (int i = 0; i < 3; i++) {
producer.send(message);
System.out.println("producing ..");
}
消費者
public void run() {
try {
ConsumerIterator<byte[], byte[]> itr = m_stream.iterator();
log.info("Kafka listener is ready to listen..");
System.out.println("listens....");
while (itr.hasNext()) {
byte[] data = itr.next().message();
System.out.println("Message received : " + data);
}
}
}
消費者屬性
enable.auto.commit=true
auto.commit.interval.ms=101
session.timeout.ms=7000
key.deserializer=org.apache.kafka.common.serialization.StringDeserializer
zookeeper.connect=zk1.xx\:2181
heartbeat.interval.ms=1000
auto.offset.reset=smallest
serializer.class=kafka.serializer.DefaultEncoder
bootstrap.servers=kk1.xx\:9092
group.id=test
consumer.timeout.ms=-1
fetch.min.bytes=1
receive.buffer.bytes=262144
你在你的kafka主題中配置了多少個分區? – jbarrueta
@jbarrueta它是默認主題..0分區 – Ratha