Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

不同组的Consumer订阅相同的一个或者多个topic问题 #59

Open
ywengineer opened this issue May 5, 2017 · 4 comments
Open

Comments

@ywengineer
Copy link

ywengineer commented May 5, 2017

一个zookeeper, 一个broker, Partition为1

不同组的Consumer订阅�相同的一个或者多个topic, 只有一个组的Consumber会收到消息。请问这是什么原因呢?

@ywengineer ywengineer changed the title 不同组的Consumer订阅同一topic问题 不同组的Consumer订阅相同的一个或者多个topic问题 May 5, 2017
@adyliu
Copy link
Owner

adyliu commented May 5, 2017

每一个partition在相同的groupId下同时只能被一个consumer消费,如果这个consumer挂了,其它consumer自动接管(在此之前是待命状态)。如果增加partition,那么其它consumer也会接管继续消费。 保证任何消息可被消费,同时却不会冲突。

如果有多个groupId,那么每个groupId之间的consumer并不冲突,各自消费,当前一个partition会被每一组groupId的一个消费。有多少groupId,那么这个partition就会被消费多少次。

@ywengineer
Copy link
Author

ywengineer commented May 5, 2017

那对Consumer分组的意义又在哪里呢?

能留个IM么?

@adyliu
Copy link
Owner

adyliu commented May 5, 2017

上面原来没有写清楚,我重新更正了下上面的回答。QQ:四一零九43200

@ywengineer
Copy link
Author

ywengineer commented May 5, 2017

以下是2个Consumer

1、不同组,消费同一topic,始终只有一个Cosumber能收到消息。另一个Consumer Group的FetchRunnable线程状态一直为Wait.

2、停掉一个Consumer Group,另一个Consumer Group的FetchRunnable线程状态一直为Wait.

3、不同Group消费不同topic也不行,另一个Consumer Group的FetchRunnable线程状态一直为Wait. 如果Consumer2的goupid与Consumer1相同,则可以消费不同的topic.

Consumer2:
JafkaConsumer consumer2 = new JafkaConsumer("group-2", "101.37.19.118", 2181) {
@OverRide
protected void onMessage(JafkaMessage message) {
System.out.println("consumer 2 onMessage => " + message.getData().readUTF());
}
};
consumer2.addTopic("demo1").start();

Consumer1:
JafkaConsumer consumer1 = new JafkaConsumer("group-1", "101.37.19.118", 2181) {
@OverRide
protected void onMessage(JafkaMessage message) {
System.out.println("consumer 1 onMessage => " + message.getData().readUTF());
}
};
consumer1.addTopic("demo1").start();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants