nchan_subscribe_existing_channels_only

The `nchan_subscribe_existing_channels_only` directive restricts subscribers to only connect to channels that already exist, preventing the creation of new channels during subscription.

Syntaxnchan_subscribe_existing_channels_only on | off;
Defaultoff
Contexthttp, server, location
Arguments1

Description

The nchan_subscribe_existing_channels_only directive, when set to on, ensures that subscribers can only connect to channels that have been previously created and are currently active within the Nchan system. This functionality is particularly useful in scenarios where channel resources need to be tightly controlled, ensuring that new channels are not created inadvertently by subscribers. By default, if a subscriber attempts to connect to a channel that does not exist, Nchan may create a new channel for them under normal circumstances; however, this directive prevents that behavior.

Setting this directive to off (the default value) allows subscribers to create new channels dynamically as they subscribe. This can lead to a proliferation of channels, which might not be desirable in every use case. This directive is often utilized in environments with complex channel management requirements, ensuring that only a defined set of channels can be operated upon by subscribers, promoting better predictability and resource management.

To implement this directive effectively, it can be included in the http, server, or location contexts of your Nginx configuration. When applied, any attempt by a subscriber to use an unknown channel ID will result in an error response, helping to maintain strict channel enforcement as dictated by the application requirements.

Config Example

location /nchan {
    nchan_subscribe_existing_channels_only on;
    nchan_pubsub;
}

When set to on, ensure that channels are pre-created; otherwise, subscribers will not receive messages from non-existent channels.

Consider the implications of channel resource management, especially in high-traffic scenarios where channel burst creation might be necessary.

← Back to all directives