nchan_eventsource_event

The `nchan_eventsource_event` directive specifies the event data for Server-Sent Events (SSE) in Nchan pub/sub systems.

Syntaxnchan_eventsource_event string;
Defaultnone
Contextserver, location, if in location
Arguments1

Description

The nchan_eventsource_event directive is essential for configuring how events are sent to clients using the Server-Sent Events (SSE) mechanism within the Nchan module of NGINX. When this directive is defined, it enables the efficient transmission of messages from the server to clients subscribed to specific channels. This behavior is crucial for real-time applications, such as live notifications, chat applications, and updates where a persistent connection exists between the server and the client, allowing the server to push updates as they occur.

This directive can accept one parameter that specifies the event data that will be included in the SSE. The parameter must follow the format appropriate for SSE events, typically being a valid string that can serve as the event's payload. When configured, Nchan will handle the outgoing message delivery formatting and ensure that the designated events are properly sent to all connected subscribers of that particular channel, potentially including multiple event types or data formats based on the application's requirements.

When using this directive in contexts such as server, location, or within conditional if statements in a location block, it allows for granular control over how events are reported. This flexibility is especially useful for implementing features where different types of events may need to be presented differently based on the context or the client’s subscription state.

Config Example

location /events {
    nchan_eventsource_event "message data";
}

Ensure that the event data is properly formatted as expected by SSE clients.

Using this directive without an accompanying subscriber setup may lead to disconnected clients not receiving any events.

Make sure Nchan is correctly included in your NGINX build as it is a third-party module.

← Back to all directives