BewareMyPower commented on issue #13965:
URL: https://github.com/apache/pulsar/issues/13965#issuecomment-1022330498
Yeah. It's weird that I also tried C++ client to consume the topic produce
by Java client with `subscriptionKeySharedUseConsistentHashing=false`, the
message loss still happened.
```c++
#include <assert.h>
#include <iostream>
#include <vector>
#include <pulsar/Client.h>
using namespace pulsar;
int main() {
Client client("pulsar://localhost:6650");
std::vector<Consumer> consumers(3);
for (size_t i = 0; i < consumers.size(); i++) {
ConsumerConfiguration conf;
conf.setConsumerType(ConsumerType::ConsumerKeyShared);
conf.setSchema(SchemaInfo(STRING, "String", ""));
conf.setSubscriptionInitialPosition(InitialPositionEarliest);
conf.setPatternAutoDiscoveryPeriod(1);
auto result =
client.subscribeWithRegex(".*KeySharedConsumerTest-multi-topics.*", "my-sub",
conf, consumers[i]);
assert(result == ResultOk);
}
std::vector<int> numReceivedList;
int numTotal = 0;
for (Consumer& consumer : consumers) {
int n = 0;
Message msg;
while (true) {
auto result = consumer.receive(msg, 3000);
if (result == ResultTimeout) {
break;
}
assert(result == ResultOk);
n++;
}
numReceivedList.emplace_back(n);
numTotal += n;
}
for (int n : numReceivedList) {
std::cout << n << std::endl;
}
std::cout << numTotal << std::endl;
client.close();
}
```
The code above is nearly the same as `Consume.java` in my repo.
But when I run C++ UT, it never failed now when
`subscriptionKeySharedUseConsistentHashing=false`
```bash
./tests/main --gtest_filter='*testMultiTopics'
```
Here are 5 test results in a row:
```
2022-01-26 23:45:25.235 INFO [0x113994600] KeySharedConsumerTest:124 |
messagesPerConsumer: {0 => 1442, 1 => 738, 2 => 820}
2022-01-26 23:45:58.855 INFO [0x1111d1600] KeySharedConsumerTest:124 |
messagesPerConsumer: {0 => 1421, 1 => 786, 2 => 793}
2022-01-26 23:46:30.804 INFO [0x11da5d600] KeySharedConsumerTest:124 |
messagesPerConsumer: {0 => 1415, 1 => 779, 2 => 806}
2022-01-26 23:47:34.651 INFO [0x1111e2600] KeySharedConsumerTest:124 |
messagesPerConsumer: {0 => 1396, 1 => 798, 2 => 806}
2022-01-26 23:47:52.039 INFO [0x111313600] KeySharedConsumerTest:124 |
messagesPerConsumer: {0 => 1371, 1 => 751, 2 => 878}
```
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]