Skip to content

Commit

Permalink
doc: infinite event example
Browse files Browse the repository at this point in the history
  • Loading branch information
pozil committed Dec 19, 2023
1 parent be3729c commit d4af346
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ See the [official Pub/Sub API repo](https://github.com/developerforce/pub-sub-ap
- [Basic Example](#basic-example)
- [Other Examples](#other-examples)
- [Publish a platform event](#publish-a-platform-event)
- [Subscribe to an infinite number of events](#subscribe-to-an-infinite-number-of-events)
- [Subscribe with a replay ID](#subscribe-with-a-replay-id)
- [Subscribe to past events in retention window](#subscribe-to-past-events-in-retention-window)
- [Handle gRPC stream lifecycle events](#handle-grpc-stream-lifecycle-events)
Expand Down Expand Up @@ -264,6 +265,25 @@ const publishResult = await client.publish('/event/Sample__e', payload);
console.log('Published event: ', JSON.stringify(publishResult));
```

### Subscribe to an infinite number of events

You may subscribe to an infinite number of events by reconnecting the client automatically when the last requested event is received.

```js
// Handle last requested event
subscription.on('lastevent', async () => {
try {
// Re-subscribe to more events
subscription = await client.subscribe(
subscription.getTopicName(),
NUMBER_OF_EVENTS
);
} catch (error) {
console.log(error);
}
});
```

### Subscribe with a replay ID

Subscribe to 5 account change events starting from a replay ID:
Expand Down

0 comments on commit d4af346

Please sign in to comment.