You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2021/09/27 08:05:08 UTC

[GitHub] [pulsar] BewareMyPower commented on issue #12189: How to get the messageID

BewareMyPower commented on issue #12189:
URL: https://github.com/apache/pulsar/issues/12189#issuecomment-927628301


   ```java
           try (PulsarClient client = PulsarClient.builder().serviceUrl("pulsar://localhost:6650").build()) {
               final String topic = "topic";
               final Consumer<byte[]> consumer = client.newConsumer()
                       .topic(topic)
                       .subscriptionName("sub")
                       .subscribe();
               final Producer<byte[]> producer = client.newProducer()
                       .topic(topic)
                       .create();
               final CountDownLatch latch = new CountDownLatch(1);
               producer.sendAsync("hello".getBytes(StandardCharsets.UTF_8)).whenComplete((id, e) -> {
                   if (e == null) {
                       System.out.println("Send to " + id + ", type: " + id.getClass().getTypeName());
                   }
                   latch.countDown();
               });
               final Message<byte[]> message = consumer.receive();
               final MessageId id = message.getMessageId();
               System.out.println("Received from " + id + ", type: " + id.getClass());
               latch.await(); // wait until send callback is triggered
           } catch (PulsarClientException | InterruptedException e) {
               e.printStackTrace();
           }
   ```


-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org