DonHaul opened a new issue #9784:
URL: https://github.com/apache/pulsar/issues/9784


   **Describe the bug**
   A clear and concise description of what the bug is.
   When using a reader to read a single message from a  partitioned topic the 
error  The partitioned topic startMessageId is illegal appears:
   
   ```
   Exception in thread "main" 
org.apache.pulsar.client.api.PulsarClientException: 
java.util.concurrent.ExecutionException: 
org.apache.pulsar.client.api.PulsarClientException: The partitioned topic 
startMessageId is illegal
        at 
org.apache.pulsar.client.api.PulsarClientException.unwrap(PulsarClientException.java:976)
        at 
org.apache.pulsar.client.impl.ReaderBuilderImpl.create(ReaderBuilderImpl.java:74)
   ```
   I implemented the code in 
https://pulsar.apache.org/docs/en/client-libraries-java/#reader which works for 
non partitioned topics.
   
   I just consumed and saved the msg id bytes into a file and then loaded that 
file as the msg_id . Is any additional parameter needed to fetch partitioned 
topics?
   
   Consumer
   ```
   Consumer consumer = client.newConsumer()
                   .topic("apache/pulsar/test-topic")
                   .subscriptionName("my-sub")
                   .subscribe();
   
               // Wait for a message
               Message msg = consumer.receive();
   
               try {
                  byte[]  by = msg.getMessageId().toByteArray();
                   FileUtils.writeByteArrayToFile(new File(".\\msg.bytes"), by);
   
               }catch (Exception e){
                   System.out.println("ERROR");
                   e.printStackTrace();
               }
   ```
   
   Reader
   ```
     byte[] msgIdBytes = FileUtils.readFileToByteArray(new 
File(".\\msg.bytes"));// Some message ID byte array
   
           System.out.println(msgIdBytes.length);
   
                   MessageId id = MessageId.fromByteArray(msgIdBytes);
           System.out.println(id);
           Reader reader = client.newReader()
                   .topic("apache/pulsar/test-topic")
                   .startMessageId(id)
                   .create();
       
   
               Message message = reader.readNext();
               // Process message
               System.out.println(message.getMessageId());
   
           client.close();
   ```
   


----------------------------------------------------------------
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:
us...@infra.apache.org


Reply via email to