push_stream_message_ttl
The `push_stream_message_ttl` directive sets the time-to-live duration for messages in channels before they are deleted.
Description
The push_stream_message_ttl directive specifies how long (in seconds) messages in the push stream channels are retained before they are considered stale and deleted. This directive impacts the push notification system by defining the lifecycle of messages, controlling the persistence of information for subscribers. For example, if a message TTL is set to 300 seconds, messages will be kept in the channel for 5 minutes after being published; after that period, they will be removed, and new subscribers attempting to retrieve them will find that they no longer exist.
Setting the TTL too high can lead to unnecessary memory consumption as messages accumulate, while a TTL that is too low might cause subscribers to miss important updates. The directive should thus be configured according to the application’s needs and expected message consumption patterns. Modifications to this setting can go into effect immediately, without requiring a full server restart, thus providing flexibility in managing message lifetimes dynamically.
This directive is defined within the HTTP context of NGINX configurations and is accompanied by the NGX_CONF_TAKE1 flag, which indicates that it requires exactly one argument (the TTL value). The value provided must be a valid time format recognized by NGINX, such as integers followed by an optional time unit (s for seconds, m for minutes, etc.).
Config Example
http {
push_stream_shared_memory_size 32M;
push_stream_message_ttl 300;
server {
location /pub {
push_stream_publisher admin;
push_stream_channels_path $arg_id;
}
location ~ /sub/(.*) {
push_stream_subscriber;
push_stream_channels_path $1;
}
}
}Make sure to specify the TTL value in seconds; not doing so will lead to configuration errors.
Ensure the TTL set is appropriate based on your application's message delivery needs to avoid premature deletion of important messages.
Restarting the server may be required if there are issues parsing the configuration after changes.