949808802 opened a new issue #10812:
URL: https://github.com/apache/pulsar/issues/10812
**Describe the bug**
In failover mode,two consumers can get message evenly。It's not just one
consumer gets all the message。
**To Reproduce**
Steps to reproduce the behavior:
producer code:
public class FailoverProducer {
public static void main(String[] args) throws Exception{
PulsarClient client = GetPulsarClient.get();
Producer<String> producer = client.newProducer(Schema.STRING)
.topic("persistent://my-tenant/my-namespace/my-topic")
.producerName("FailoverProducer")
.create();
for (int i =0 ;i<10;i++){
String msg = "hello-"+i;
producer.send(msg);
System.out.println("send a message:" + msg);
}
}
}
masterConsumer code:
public class FailoverConsumerMaster {
public static void main(String[] args) throws Exception{
Consumer<String> consumerMaster =
GetPulsarClient.get().newConsumer(Schema.STRING)
.topic("persistent://my-tenant/my-namespace/my-topic")
.subscriptionName("failover-subscription")
.subscriptionType(SubscriptionType.Failover)
.priorityLevel(0)
.consumerName("master")
.subscribe();
while (true) {
Message<String> message = consumerMaster.receive();
try {
System.out.println("consumer-master-Message received: "+
message.getValue());
consumerMaster.acknowledge(message);
}catch (Exception e) {
System.out.println(e);
consumerMaster.negativeAcknowledge(message);
}
}
}
}
another consumer code:
public class FailoverConsumerStandby {
public static void main(String[] args) throws Exception{
Consumer<String> consumerStandby =
GetPulsarClient.get().newConsumer(Schema.STRING)
.topic("persistent://my-tenant/my-namespace/my-topic")
.subscriptionName("failover-subscription")
.subscriptionType(SubscriptionType.Failover)
.priorityLevel(999)
.consumerName("standby")
.subscribe();
while (true) {
Message<String> message = consumerStandby.receive();
try {
System.out.println("consumer-standby-Message received: "+
message.getValue());
consumerStandby.acknowledge(message);
}catch (Exception e) {
System.out.println(e);
consumerStandby.negativeAcknowledge(message);
}
}
}
}
**Expected behavior**
Master consumer can get all message,another consumer can‘t get any
message,When master consumer disconnected,another consumer can get all message.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]