All Implemented Interfaces:
Notifier
Direct Known Subclasses:
DingTalkNotifier, DiscordNotifier, FeiShuNotifier, HipchatNotifier, LetsChatNotifier, MattermostNotifier, RocketChatNotifier, SlackNotifier, TelegramNotifier, WebexNotifier

public abstract class AbstractContentNotifier extends AbstractStatusChangeNotifier
Base class for notifiers that generate message content from templates using Spring Expression Language (SpEL).

This class provides a framework for creating custom notifiers that format notification messages using SpEL templates with access to instance event data. Subclasses must implement two methods:

Usage Example:


 public class EmailNotifier extends AbstractContentNotifier {
     public EmailNotifier(InstanceRepository repository) {
         super(repository);
     }

     @Override
     protected Map<String, Object> getContent(InstanceEvent event, Instance instance) {
         var content = super.getContent(event, instance);
         content.put("customContent", "Hello, World!");
         return content;
     }



&#64;Override
     protected String getDefaultMessage() {
         return "#{name} is #{status} at #{url}";
     }
 }
 

The message template can be customized at runtime using setMessage(String).

  • Constructor Details

  • Method Details

    • getMessage

      public String getMessage()
    • setMessage

      public void setMessage(String message)
    • createContent

      protected String createContent(InstanceEvent event, Instance instance)
      Generates the notification message content by evaluating the SpEL template with event and instance data.

      This method combines the configured message template with the data provided by buildContentModel(InstanceEvent, Instance) to produce the final notification text.

      Parameters:
      event - the instance event that triggered the notification
      instance - the instance associated with the event
      Returns:
      the evaluated message content as a string
    • buildContentModel

      protected Map<String,Object> buildContentModel(InstanceEvent event, Instance instance)
      Provides the data model used for evaluating the message template.

      The returned map contains key-value pairs that can be referenced in the SpEL template using #{key} syntax. For example, if the map contains {"name": "MyApp", "status": "UP"}, the template "#{name} is #{status}" would evaluate to "MyApp is UP".

      Parameters:
      event - the instance event containing event-specific data
      instance - the instance containing registration and status information
      Returns:
      a map of template variables and their values
    • getDefaultMessage

      protected abstract String getDefaultMessage()
      Defines the default SpEL template string used for message generation.

      The template should use #{key} syntax to reference variables provided by buildContentModel(InstanceEvent, Instance). This default can be overridden at runtime using setMessage(String).

      Returns:
      the default SpEL template string (e.g., "#{name} is #{status}")