push_stream_store_messages
The `push_stream_store_messages` directive enables the storage of messages for push streams, allowing subscribers to receive messages that were sent when they were offline.
Description
The push_stream_store_messages directive is an essential part of the NGINX Push Stream Module, as it dictates whether messages published to a channel are stored for later retrieval by subscribers. When enabled, this feature provides resilience in communication, ensuring that subscribers can pull previously sent messages if they connect after the messages were broadcasted. The directive accepts a single argument which can be set to 'on' or 'off'. When set to 'on', this allows the server to cache messages in memory or a designated shared memory area, supporting user applications that might need to send data in real-time while also allowing for message persistence.
This directive is typically configured in the http, server, or location context, depending on the desired scope of message storage. Using shared memory effectively requires configuring the required shared memory space to handle the volume of messages, which can be achieved with the push_stream_shared_memory_size directive. It is important to consider the implications of memory usage depending on the expected load and message retention requirements. Also, once messages are stored, they adhere to any life cycle settings dictated by the push_stream_message_ttl, which denotes how long (in seconds) messages should remain available for retrieval after being published.
Config Example
http {
push_stream_shared_memory_size 32M;
server {
location /pub {
push_stream_publisher admin;
push_stream_store_messages on;
}
location ~ /sub/(.*) {
push_stream_subscriber;
push_stream_store_messages on;
}
}
}Ensure that push_stream_shared_memory_size is adequately configured to accommodate the stored messages.
Monitor memory usage when enabling message storage, especially under heavy load, to prevent server resource exhaustion.
Mismatched settings between publishers and subscribers regarding message storage can lead to confusion about message availability.