Expected behavior
message redelivery
Actual behavior
Message cannot be redelivered
Steps to reproduce
producer code:
public static void main(String[] args) throws PulsarClientException, InterruptedException {
String token = "xxx";
PulsarClient client = PulsarClient.builder()
.serviceUrl("xxx")
.authentication(AuthenticationFactory.token(token))
.memoryLimit(64, SizeUnit.MEGA_BYTES)
.build();
Producer<String> producer = client.newProducer(Schema.STRING)
.topic("xxx")
.messageRoutingMode(MessageRoutingMode.RoundRobinPartition)
.enableBatching(true)
.batchingMaxBytes(1048576)
.batchingMaxMessages(10000)
.batchingMaxPublishDelay(100, TimeUnit.MILLISECONDS)
.blockIfQueueFull(true)
.create();
long i = 0;
while (true) {
i++;
producer.sendAsync("Message " + i).thenAccept(msgId -> {
System.out.println("Message " + msgId + " successfully sent");
});
if(i>10)break;
}
}
consumer code:
public static void main(String[] args) throws PulsarClientException {
String token = "xxx";
PulsarClient client = PulsarClient.builder()
.serviceUrl("xxx")
.authentication(AuthenticationFactory.token(token))
.memoryLimit(64, SizeUnit.MEGA_BYTES)
.build();
Consumer<String> consumer = client.newConsumer(Schema.STRING)
.topic("xxx")
.subscriptionName("xxx")
.subscriptionType(SubscriptionType.Exclusive)
.receiverQueueSize(1000)
.batchReceivePolicy(BatchReceivePolicy.builder()
.maxNumMessages(1000)
.maxNumBytes(1024 * 1024 * 10)
.timeout(10, TimeUnit.MILLISECONDS)
.build())
.subscribe();
while (true) {
Messages<String> msgs = consumer.batchReceive();
msgs.forEach(obj -> {
Message msg = null;
try {
msg = (Message) obj;
System.out.println("Message received: " + msg.getValue());
consumer.acknowledge(msg);
} catch (Exception e) {
// Message processing failed, resend later
}finally {
//Test: After each confirmation, cancel the confirmation again to make the message redelivery
consumer.negativeAcknowledge(msg);
}
});
}
}
use "consumer.negativeAcknowledge(msg)" or "consumer.negativeAcknowledge(new MessageIdImpl(x,x,x))" After executing the consumer program, no message redelivery was found
System configuration
Pulsar version: 2.9.2/2.8.2
Expected behavior
message redelivery
Actual behavior
Message cannot be redelivered
Steps to reproduce
producer code:
consumer code:
use "consumer.negativeAcknowledge(msg)" or "consumer.negativeAcknowledge(new MessageIdImpl(x,x,x))" After executing the consumer program, no message redelivery was found
System configuration
Pulsar version: 2.9.2/2.8.2