visortelle commented on issue #22529:
URL: https://github.com/apache/pulsar/issues/22529#issuecomment-2067251332

   @ragaur-tibco I fixed your code.
   
   Code:
   
   ```java
   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:
   
   ```
     a mvn exec:java                                                            
                                                                                
       <aws:aws-superadmin> <region:us-east-2>
   [INFO] Scanning for projects...
   [INFO] 
   [INFO] --------------------------------< c:a 
>---------------------------------
   [INFO] Building a 1.0-SNAPSHOT
   [INFO] --------------------------------[ jar 
]---------------------------------
   [INFO] 
   [INFO] --- exec-maven-plugin:3.2.0:java (default-cli) @ a ---
   SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
   SLF4J: Defaulting to no-operation (NOP) logger implementation
   SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further 
details.
   Received message from topic non-persistent://my-tenant/new-name/topic-non-1: 
=========from topic non-persistent://my-tenant/new-name/topic-non-1 
   Received message from topic persistent://my-tenant/new-name/topic-pers-1: 
=========from topic persistent://my-tenant/new-name/topic-pers-1 
   ```


-- 
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]

Reply via email to