The definition of a consumer in NATS is
A consumer is a stateful view of a stream. It acts as interface for clients to consume a subset of messages stored in a stream and will keep track of which messages were delivered and acknowledged by clients.
I'm more interested in understanding what exactly is a consumer under the hood ? Is it a process, a thread, some kind of socket i.e. a network entity etc ?
I'm designing a system where I'm using NATS 2.9, so a consumer can't have more than one subject filter. I want to create 1 consumer per subject filter and I'm concerned about the performance & resource implications of creating about 10,000 consumers in the worst case.
Is a consumer an expensive resource to create in NATS ?
Creating a single consumer with a very generic subject filter is an alternative I'm considering but it doesn't fit into my design neatly as several go routines will be sharing this one global consumer as opposed to creating one consumer per go routine, each go routine will consume and process its own subject filter's messages thus ensuring a sort of logical isolation as far as my design goes.
They are extremely cheap. Basically, a connection to NATS is a multiplexer:
I created a test setup where I was able to easily have 1500 consumers on a single machine (my laptop), including a NATS cluster and a producer with the whole setup still being able to send and receive several million
"Hello, World!"s per second. I actually needed to scale up the producers considerably to even manage to get any meaningful data.The environment
Dockerfile
We create a Docker image from the binaries you will find below. It is pretty much standard.
docker-compose.yaml
The Services
Producer
Note that you might need to scale up the producer in order to get meaningful data.
Consumer
Also, pretty much standard:
If interested, I can publish the code and stuff on GitHub.