apache / apache/pulsar

Consumer able to receive message which is not matching the regex pattern

Open
#22,529 9 comments 0 reactions 0 assignees View on GitHub
type/bug
Dominant language
Java
Stars
15.3k
Forks
3.8k
Avg merge
1d 14h
Merged PRs (30d)
160

Description

### Search before asking

- [X] I searched in the [issues](https://github.com/apache/pulsar/issues) and found nothing similar.

### Read release policy

- [X] I understand that unsupported versions don't get bug fixes. I will attempt to reproduce the issue on a supported version of Pulsar client and Pulsar broker.

### Version

3.2.2

### Minimal reproduce step

Steps to reproduce:

- send messages to multiple topics using producer
- consumer provide the regex pattern topic name: **non-persistent://my-tenant/new-name.***
- provide the subscriptionTopicsMode = AllTopics

### What did you expect to see?

- Consumer should be able to consume messages from the topic starts with **non-persistent://my-tenant/new-name**

### What did you see instead?

- Consumer was able to consume messages from the topic starts with persistent as well

```java
package Pulsar;

import org.apache.pulsar.client.admin.PulsarAdmin;
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 AllTopicsConsumerExample {
private static PulsarAdmin adm;
private static final String SERVICE_URL = "pulsar://localhost:6650";
private static final String NAMESPACE = "my-tenant/new-name";
private static final String SUBSCRIPTION_NAME = "your-subscription";

public static void main(String[] args) throws PulsarClientException {
PulsarClient pulsarClient = PulsarClient.builder()
.serviceUrl(SERVICE_URL)
.build();

Producer producer = pulsarClient.newProducer(Schema.STRING)
.topic("non-persistent://my-tenant/new-name/topic-non-1")
.enableBatching(false).create();
producer.send("=========from topic non-persistent://my-tenant/new-name/topic-non-1 ");
System.out.println("new producer");
Producer producer1 = pulsarClient.newProducer(Schema.STRING)
.topic("persistent://my-tenant/new-name/topic-pers-1")
.enableBatching(false).create();
producer1.send("=======from topic persistent://my-tenant/new-name/topic-pers-1 ");

Pattern allTopicsPattern = Pattern.compile("non-persistent://my-tenant/new-name/.*");

Consumer allTopicsConsumer = pulsarClient.newConsumer()
.topicsPattern(allTopicsPattern)
.subscriptionName(SUBSCRIPTION_NAME).subscriptionTopicsMode(RegexSubscriptionMode.valueOf("AllTopics"))
.subscribe();

while (true) {
Message message = allTopicsConsumer.receive();
System.out.println("Received message from topic " + message.getTopicName()
+ ": " + new String(message.getValue()));
allTopicsConsumer.acknowledge(message);
}
}
}
```

![image](https://github.com/apache/pulsar/assets/119859927/e72d984a-60c2-4ffe-b72f-f91579919c8a)

### Anything else?

_No response_

### Are you willing to submit a PR?

- [ ] I'm willing to submit a PR!

Contributor guide

Open the contributing guide

Research direction

Start with the Java reproducer in the issue and trace the topicsPattern and subscriptionTopicsMode=AllTopics consumer path. Verify why a persistent topic is delivered for the non-persistent regex, then add or update coverage for the expected topic filtering behavior; the issue names no repository file or test path.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
distributed-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.