Is it a bad practice to send message larger than 1MB over NATS? For example a JSON response whose size is about 2MB. If it is a bad practice, would breaking the message down into smaller responses be a better approach, or does NATS support sending back multiple responses to a single request? (An example in C#, Node, or Java would be really appreciated).
Asked
Active
Viewed 591 times
1 Answers
1
The size limit is 1 MB - look at Is there a message size limitation in NATS?
Messages larger than the size limit are not sent. You can increase the size limit in the server settings, but the NATS people probably had a good reason for that limit, so I wouldn't recommend it.
The Request-Reply pattern doesn't provide for multiple replies to a request. In similar cases, I proceed like this:
- Requester: Create a new unique subject name, e.g. UUID.
- Requester: Subscribe to that subject.
- Requester: Send a message with "reply-to" set to that subject.
- Requester: Collect all responses that arrive on the subject until either an "end of response" message arrives or a timeout is reached.
Code the "responder" so it gives the requester what it needs (among others: the "end of response" message).
That way, you can split large responses e.g. into 1 MB blocks.

Georg
- 966
- 8
- 25
-
I already know all these, but I wanna know if it is a bad practice to send messages larger than 1MB. Can you provide a yes or no answer and then describe why it is so? – Arnold Zahrneinder Oct 21 '20 at 13:30
-
2I'm sorry you consider my response as "not helpful" although I did provide a clear answer to "does NATS support sending back multiple responses?" as well as to the implicit question "CAN I send larger messages?". Obviously, I did not understand the intent of your question right. - And no, I'm afraid I don't have a "yes/no" answer with compelling reasons. – Georg Oct 22 '20 at 15:47