zyllt commented on issue #6785:
URL: https://github.com/apache/pulsar/issues/6785#issuecomment-618136728
Use the following code to reproduce the problem:
```
public static void main(String[] args) throws PulsarClientException {
PulsarClient client = getPulsarClient();
String subName = "sub-1";
String topicName = "persistent://public/default/topic";
Consumer<String> consumer1 = null;
try {
consumer1 = client.newConsumer(Schema.STRING).topic(topicName +
"1", topicName + "2").consumerName("c-1")
.subscriptionName(subName)
.subscriptionInitialPosition(SubscriptionInitialPosition.Earliest)
.messageListener((consumer, msg) -> {
try {
String hexString =
Hex.encodeHexString(msg.getMessageId().toByteArray());
MessageId messageId =
MessageId.fromByteArrayWithTopic(Hex.decodeHex(hexString.toCharArray()),
msg.getTopicName());
consumer.acknowledge(messageId);
} catch (Exception e) {
e.printStackTrace();
}
})
.subscribe();
System.out.println("consumer1 start!");
} catch (PulsarClientException e) {
e.printStackTrace();
}
}
```
the exception:
```
java.lang.IllegalArgumentException
at
org.apache.pulsar.shade.com.google.common.base.Preconditions.checkArgument(Preconditions.java:127)
at
org.apache.pulsar.client.impl.MultiTopicsConsumerImpl.doAcknowledge(MultiTopicsConsumerImpl.java:450)
at
org.apache.pulsar.client.impl.ConsumerBase.doAcknowledgeWithTxn(ConsumerBase.java:294)
at
org.apache.pulsar.client.impl.ConsumerBase.acknowledgeAsync(ConsumerBase.java:262)
at
org.apache.pulsar.client.impl.ConsumerBase.acknowledgeAsync(ConsumerBase.java:250)
at
org.apache.pulsar.client.impl.ConsumerBase.acknowledge(ConsumerBase.java:187)
```
The reason for this bug is:
1.`MultiTopicsConsumerImpl#doAcknowledge` requires a `MessageId` of type
`TopicMessageIdImpl`.
https://github.com/apache/pulsar/blob/c36170c3acc0bd432036baf7d9471a4c34320395/pulsar-client/src/main/java/org/apache/pulsar/client/impl/MultiTopicsConsumerImpl.java#L449
2.when the topics in `MultiTopicsConsumerImpl#topics` is
non-partitioned-topic,`MessageId#fromByteArrayWithTopic`can only get
`BatchMessageIdImpl` or `MessageIdImpl`
https://github.com/apache/pulsar/blob/c36170c3acc0bd432036baf7d9471a4c34320395/pulsar-client/src/main/java/org/apache/pulsar/client/impl/MessageIdImpl.java#L140
----------------------------------------------------------------
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]