Buffering Messages During Reconnect Attempts

    During a short reconnect, the client can allow applications to publish messages that, because the server is offline, will be cached in the client. The library will then send those messages once reconnected. When the maximum reconnect buffer is reached, messages will no longer be publishable by the client and an error will be returned.

    Be aware, while the message appears to be sent to the application it is possible that it is never sent because the connection is never remade. Your applications should use patterns like acknowledgements to ensure delivery.

    For clients that support this feature, you are able to configure the size of this buffer with bytes, messages or both.

    Java

    1. server("nats://demo.nats.io:4222").
    2. reconnectBufferSize(5 * 1024 * 1024). // Set buffer in bytes
    3. Connection nc = Nats.connect(options);
    4. nc.close();

    JavaScript

    Python

    TypeScript

    1. // Reconnect buffer size is not configurable on NATS TypeScript client

    C