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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to