nchan_subscriber_first_message

The `nchan_subscriber_first_message` directive configures the behavior of a subscriber by determining whether it should receive the first published message from the channel upon subscribing.

Syntaxnchan_subscriber_first_message on | off;
Defaultoff
Contextserver, location, if in location
Arguments1

Description

The nchan_subscriber_first_message directive is utilized within the context of a publisher/subscriber setup to configure the behavior of subscribers when they connect to a channel. Specifically, it controls whether or not a subscriber should receive the very first message that has been published to that channel upon establishing a connection. This feature can be particularly useful in scenarios where subscribers need to be brought up to speed with the latest content in a channel immediately upon subscription.

The directive can be applied at the server, location, or within an 'if' block in a location. By setting this directive, administrators can provide fine-tuned behavior for subscribers, allowing for a more responsive and informed subscriber experience when they connect for the first time. Notably, it streamlines the process of message delivery in real-time applications, enhancing user engagement by immediately delivering relevant information as soon as they start listening to a channel.

It is important to consider the implications of this behavior on message delivery guarantees, as enabling the first message sending can lead to increased payloads depending on the timing and frequency of published messages. Additionally, the behavior might differ based on the method of subscription, such as using WebSocket or EventSource, each having its nuances in how connections and messages are handled.

Config Example

location /subscribe {
    nchan_subscriber_first_message on;
    nchan_subscriber_channel_id my_channel;
}

Make sure not to enable if you do not want subscribers to receive outdated or irrelevant messages upon connecting.

Ensure that the message delivery method (WebSocket, SSE, etc.) supports first message delivery to avoid unexpected behavior.

← Back to all directives