https://github.com/context-labs/nats-consume-concurrency
https://github.com/context-labs/nats-consume-concurrency
Last synced: 11 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/context-labs/nats-consume-concurrency
- Owner: context-labs
- Created: 2025-01-31T02:48:23.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-01-31T02:57:29.000Z (over 1 year ago)
- Last Synced: 2025-06-06T03:34:21.077Z (about 1 year ago)
- Language: TypeScript
- Size: 6.84 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# NATS Consume Concurrency
This example demonstrates how NATS JetStream handles message consumption concurrency using a callback method.
To run the example, install dependencies with `bun` or `npm`, then run with `bun run index.ts` or `npx tsx index.ts`.
You can edit `MAX_CONCURRNECY` and `NUMBER_OF_CONCURRENT_MESSAGES_TO_PUBLISH` to see how the behavior changes with different numbers of messages and concurrency.
This currently demonstrates two major issues:
1. The concurrency limit is not respected. All messages are being processed within 10-20ms, despite multiple batches of max messages being sent and long wait times in the callback.
2. The NATS connection is not draining properly, we have outstanding messages that are not done being processed.
Potential sources of the issues:
- NATS does not await a callback to finish, it simply continues when the function returns. I would consider this a NATS bug since the callback is supposed to be a promise. Will dig into their code to see if this is the case.