Skip to content

Commit fad8daa

Browse files
author
magne
committed
chore: add error log and update readme
1 parent b6f173b commit fad8daa

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,25 @@ const consumer = await client.declareConsumer(consumerOptions, (message: Message
245245
// ...
246246
```
247247

248+
Optionally a single active consumer can have a callback which returns an offset that will be used once the consumer becomes active
249+
250+
```typescript
251+
const consumerOptions = {
252+
stream: "stream-name",
253+
offset: Offset.next(),
254+
singleActive: true,
255+
consumerRef: "my-consumer-ref",
256+
consumerUpdateListener: async (consumerReference, streamName) => {
257+
const offset = await client.queryOffset({ reference: consumerReference, stream: streamName })
258+
return rabbit.Offset.offset(offset)
259+
},
260+
}
261+
262+
// ...
263+
```
264+
265+
Check `example/single_active_consumer_update_example.js` for a basic usage example.
266+
248267
### Custom Policy
249268

250269
By default the client uses the `creditsOnChunkCompleted(1, 1)` policy. This policy grants that messages will be processed in order, as a new chunk will only be requested once the current chunk has been processed. It is possible to override this policy by passing `creditPolicy` to the consumer options. Be aware that modifying this policy can lead to out-of-order message processing.

src/client.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,9 @@ export class Client {
606606
const offset = await consumer.consumerUpdateListener(consumer.consumerRef, consumer.streamName)
607607
return offset
608608
} catch (error) {
609+
this.logger.error(
610+
`Error in consumerUpdateListener for consumerRef ${consumer.consumerRef}: ${(error as Error).message}`
611+
)
609612
return consumer.offset
610613
}
611614
}

0 commit comments

Comments
 (0)