Skip to content

Commit

Permalink
Document consumer pause & resume
Browse files Browse the repository at this point in the history
Fixes #40
  • Loading branch information
Nevon committed Mar 9, 2018
1 parent 8d4422c commit 84091c7
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ __In active development - alpha__
- [eachMessage](#consuming-messages-each-message)
- [eachBatch](#consuming-messages-each-batch)
- [Options](#consuming-messages-options)
- [Pause & Resume](#consuming-messages-pause-resume)
- [Custom assigner](#consuming-messages-custom-assigner)
- [Seek](#consuming-messages-seek)
- [Describe group](#consuming-messages-describe-group)
Expand Down Expand Up @@ -425,6 +426,36 @@ await consumer.disconnect()
- __maxWaitTimeInMs__ - The maximum amount of time in milliseconds the server will block before answering the fetch request if there isn’t sufficient data to immediately satisfy the requirement given by `minBytes`. default: `5000`,
- __retry__ - default: `{ retries: 10 }`

#### <a name="consuming-messages-pause-resume"></a> Pause & Resume

In order to pause and resume consuming from one or more topics, the `Consumer` provides the methods `pause` and `resume`.

```javascript
await consumer.connect()

await consumer.subscribe({ topic: 'jobs' })
await consumer.subscribe({ topic: 'pause' })
await consumer.subscribe({ topic: 'resume' })

await consumer.run({ eachMessage: async ({ topic, message }) => {
switch(topic) {
case 'jobs':
doSomeWork(message)
break
case 'pause':
// Stop consuming from the 'jobs' topic
consumer.pause([{ topic: 'jobs' }])
break
case 'resume':
// Resume consming from the 'jobs' topic
consumer.resume([{ topic: 'jobs' }])
break
}
}})
```

Calling `pause` with a topic that the consumer is not subscribed to is a no-op, as is calling `resume` with a topic that is not paused.

#### <a name="consuming-messages-custom-assigner"></a> Custom assigner

TODO: write
Expand Down

0 comments on commit 84091c7

Please sign in to comment.