broker-game / git-broker-client

A Slow Event Messaging/Streaming client using Git for educational purposes
Apache License 2.0
1 stars 0 forks source link

Add support for Consumer::receive #115

Open jabrena opened 4 years ago

jabrena commented 4 years ago
Message<T> receive() throws PulsarClientException
Receives a single message.
This calls blocks until a message is available.

while (true) {
  // Wait for a message
  Message msg = consumer.receive();

  try {
      // Do something with the message
      System.out.printf("Message received: %s", new String(msg.getData()));

      // Acknowledge the message so that it can be deleted by the message broker
      consumer.acknowledge(msg);
  } catch (Exception e) {
      // Message failed to process, redeliver later
      consumer.negativeAcknowledge(msg);
  }
}