nchan_channel_event_string
The `nchan_channel_event_string` directive allows you to define a custom event string associated with a specific Nchan channel.
Description
The nchan_channel_event_string directive is used in Nchan to assign a specific event identifier string that can be sent and received across Nchan channels. It serves as a way to customize the event payload that subscribers will receive upon message publication. This directive can take a single argument: the string that will be sent as an event when a message is published to the associated channel.
When configured, this event string is included in the message delivery process, allowing subscribers to easily filter or react to specific types of events. This can be particularly useful in applications where different types of messages may require different handling logic on the client side. The context where this directive can be used includes server, location, or within an if block in a location, enabling flexible application of its functionality based on the request URL or conditions.
It is important to ensure that the event string is meaningful within the context of your application logic, as it can influence subscriber behavior, particularly in web applications where clients are listening for specific event types or messages. If no value is specified, the behavior defaults to sending a generic event, which may not suit applications that need specific event handling mechanisms.
Config Example
location /pub {
nchan_channel_event_string "custom_event";
}
location /sub {
nchan_subscriber_channel_id $arg_channel;
}Ensure that the event string is unique if multiple channels are used to avoid confusion for subscribers.
Be careful when using dynamic variables in the event string as they may not resolve as expected in certain contexts.
Consider the impact of changing the event string on existing subscribers; it may break expected behavior.