apache / apache/pulsar

[Doc] Include ReaderListener example in Reader interface

Open
#19,728 3 comments 0 reactions 1 assignee Claimed by @paulkmoore View on GitHub
doc-required Stale
Dominant language
Java
Stars
15.3k
Forks
3.8k
Avg merge
1d 14h
Merged PRs (30d)
160

Description

### Search before asking

- [X] I searched in the [issues](https://github.com/apache/pulsar/issues) and found nothing similar.

### What issue do you find in Pulsar docs?

I think it would be useful to introduce the ReaderListener in the [Reader interface introduction](https://pulsar.apache.org/docs/2.11.x/concepts-clients/#reader-interface).

Whilst there is obviously a balance here, I think most (especially new) users would want to understand that there is a better way of processing messages than the documented `while(true)` loop.

### What is your suggestion?

I would add something like the following:

Messages can be processed by registering an implementation of a [ReaderInterface](https://pulsar.apache.org/api/client/2.11.x/org/apache/pulsar/client/api/ReaderListener.html) as follows:

```
Reader reader = pulsarClient.newReader()
.topic(topic)
.startMessageId(MessageId.latest)
.readerListener((ReaderListener) (reader, msg) -> {
// Process the message
})
.create();
```

### Any reference?

_No response_

### Are you willing to submit a PR?

- [X] I'm willing to submit a PR!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.