Implementing messaging with NATS JetStream
NATS (https://nats.io) is a very popular messaging broker that supports subject-based messaging and publish-subscribe (pub-sub). Core NATS also supports load-balanced queue groups, so the competing consumer pattern can be used to scale up for higher message processing rates. It does not support, at least at the time of writing this book, partitioned queues.
NATS is capable of distributing millions of messages a second and, compared with many other message brokers, it has an easy-to-use API and message model, as described here:
- Subject: A string containing where the message is to be published or was published to.
- Payload: A byte slice capable of holding up to 64 megabytes (MB); the NATS maintainers recommend smaller sizes, though.
- Headers: A map of string slices indexed with strings, not unlike the headers from the standard library
http
package. - Reply: A string used to handle replying to an asynchronous request; we will...