https://nats.io/documentation/faq/#ordering
NATS implements source ordered delivery per publisher.
Does NATS guarantee message ordering in the following case of a login service subscribing subjects from a users service, where all messaging runs on a single NATS cluster (without NATS streaming):
Use case: A users service (Java client) listens on subject "query.users" for a request message. When a message arrives, it publishes the current users list to the response subject. In the users service, new users can be created, resulting in update messages being published in the "users.updates" subject.
If a login service on startup first subscribes to "users.updates" and immediately afterwards queries "query.users", it will receive the current users list and updates for that list, so it can hold an eventual consistent copy of the users list.
Question: If the users service receives a "query.users" query and sends the users list as response (in the query-generated subject), and immediately afterwards sends an update message in the "users.updates" subject,
is is guaranteed that
- the login service will first receive the query response in the generated subject, and then the update message in the "users.updates" subject, or
- the login service will receive both messages, but in indetermiate order,
or could it happen that the subscription to "users.updates" is not established fast enough and the login service never receives the update message, but does receive the queried users list?
Or, the same question, more abstract:
A NATS cluster, no NATS streaming...
Java client A has a dispatcher listening to subject X. When a message arrives, it first publishes a response to the replyTo subject, and immediately afterwards publishes a message to the Y subject.
If Java client B first subscribes to Y, and immediately afterwards sends a query to subject X, we expect that the client B will recieve both the response and the message.
Is it guaranteed, that client B will
- first receive the response and then the message on Y, or
- receive both messages, but in indetermiate order,
or could it happen that the subscription to Y is not established fast enough and client B never receives the message on Y, although it receives the response to its query?