-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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 able to receive message which is not matching the regex pattern #22529
Comments
According to #19798, there is no need to specify
|
ok Thank you @visortelle means for non-persistent it is not working properly for non-persistent topic. |
@ragaur-tibco I completely agree and don't argue with that. |
@ragaur-tibco the current behavior is correct. See my comment here: #22527 (comment) |
@ragaur-tibco I fixed your code.
Source: https://pulsar.apache.org/docs/next/cookbooks-non-persistent/#overview In your code, the subscriber was created after messages were sent. Code: package b;
import org.apache.pulsar.client.admin.PulsarAdminException;
import org.apache.pulsar.client.api.*;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
public class App {
private static final String SERVICE_URL = "pulsar://localhost:6650";
private static final String SUBSCRIPTION_NAME = "your-subscription";
public static void main(String[] args) throws Exception {
PulsarClient pulsarClient = PulsarClient.builder()
.serviceUrl(SERVICE_URL)
.build();
Producer<String> producerA = pulsarClient.newProducer(Schema.STRING)
.topic("non-persistent://my-tenant/new-name/topic-non-1")
.enableBatching(false).create();
Producer<String> producerB = pulsarClient.newProducer(Schema.STRING)
.topic("persistent://my-tenant/new-name/topic-pers-1")
.enableBatching(false).create();
Pattern allTopicsPattern = Pattern.compile("my-tenant/new-name/.*");
Consumer<byte[]> allTopicsConsumer = pulsarClient.newConsumer()
.topicsPattern(allTopicsPattern)
.subscriptionName(SUBSCRIPTION_NAME)
.subscriptionTopicsMode(RegexSubscriptionMode.AllTopics)
.subscribe();
producerA.send("=========from topic non-persistent://my-tenant/new-name/topic-non-1 ");
producerB.send("=========from topic persistent://my-tenant/new-name/topic-pers-1 ");
while (true) {
Message<byte[]> message = allTopicsConsumer.receive();
System.out.println("Received message from topic " + message.getTopicName()
+ ": " + new String(message.getValue()));
allTopicsConsumer.acknowledge(message);
}
}
} Logs:
|
@ragaur-tibco please check and let me know if it resolves the issue. |
Hi @visortelle I tried creating subscriber before sending the messages
response: only getting the response from persistent topic but not from non-persistent |
Interesting. My observation is that after we create a pattern consumer, for an existing non-persistent topic it doesn't "immediately" create the underlying subscription and consumers if there are no connected producers at this moment. But it will eventually be created after a short time. TIP: you can display the list of the underlying consumers by casting your consumer to List<ConsumerImpl<byte[]>> consumers =
((PatternMultiTopicsConsumerImpl<byte[]>) allTopicsConsumer).getConsumers();
for (ConsumerImpl<byte[]> consumer : consumers) {
System.out.println("consumer: " + consumer.getTopic());
} If you modify your code to send a lot of messages asynchronously, you'll start to receive them after a short time. for (int i = 0; i < 100000; i++) {
producer.sendAsync("=========from topic non-persistent://tenant-1/name/topic-1 " + i);
}
I don't know if it can qualify as a bug. cc @lhotari @ragaur-tibco do you have a real use-case in mind? I wouldn't rely on non-persistent topics if losing a non-significant amount of messages could affect my application. |
Here is the reason. Before adding a topic to the topics list, it checks that the topic pulsar/pulsar-broker/src/main/java/org/apache/pulsar/broker/namespace/NamespaceService.java Line 1519 in 21647a1
Line 993 in 21647a1
|
Search before asking
Read release policy
Version
3.2.2
Minimal reproduce step
Steps to reproduce:
What did you expect to see?
What did you see instead?
Anything else?
No response
Are you willing to submit a PR?
The text was updated successfully, but these errors were encountered: