class {
/**
* Called when a message is received on a subscribed channel
* @channel The channel that received the message
* @message The message content
*/
public void function onMessage( string channel, string message ) {
println( "Message received on #arguments.channel#: #arguments.message#" );
// Process message based on channel
switch( arguments.channel ) {
case "notifications":
handleNotification( arguments.message );
break;
case "alerts":
handleAlert( arguments.message );
break;
default:
logMessage( arguments.channel, arguments.message );
}
}
/**
* Called when a message is received on a pattern-subscribed channel
* @pattern The pattern that matched
* @channel The actual channel name
* @message The message content
*/
public void function onPMessage( string pattern, string channel, string message ) {
println( "Pattern message: pattern=#arguments.pattern#, channel=#arguments.channel#, message=#arguments.message#" );
}
/**
* Called when successfully subscribed to a channel
* @channel The channel subscribed to
* @subscribedChannels Total number of channels now subscribed to
*/
public void function onSubscribe( string channel, numeric subscribedChannels ) {
println( "Subscribed to #arguments.channel# (total channels: #arguments.subscribedChannels#)" );
}
/**
* Called when unsubscribed from a channel
* @channel The channel unsubscribed from
* @subscribedChannels Remaining subscribed channels
*/
public void function onUnsubscribe( string channel, numeric subscribedChannels ) {
println( "Unsubscribed from #arguments.channel# (remaining: #arguments.subscribedChannels#)" );
}
/**
* Called when successfully subscribed to a pattern
* @pattern The pattern subscribed to
* @subscribedChannels Total number of patterns now subscribed to
*/
public void function onPSubscribe( string pattern, numeric subscribedChannels ) {
println( "Subscribed to pattern #arguments.pattern# (total patterns: #arguments.subscribedChannels#)" );
}
/**
* Called when unsubscribed from a pattern
* @pattern The pattern unsubscribed from
* @subscribedChannels Remaining subscribed patterns
*/
public void function onPUnsubscribe( string pattern, numeric subscribedChannels ) {
println( "Unsubscribed from pattern #arguments.pattern# (remaining: #arguments.subscribedChannels#)" );
}
// Helper methods
private void function handleNotification( string message ) {
// Custom notification handling logic
}
private void function handleAlert( string message ) {
// Custom alert handling logic
}
private void function logMessage( string channel, string message ) {
// Custom logging logic
}
}