Class NATSStreamingNotificationReceiver

All Implemented Interfaces:
NotificationIndexCleanup.Listener, NotificationReceiver, Configurable, io.nats.streaming.MessageHandler

public class NATSStreamingNotificationReceiver extends DefaultNotificationReceiver implements io.nats.streaming.MessageHandler
Connects directly to a NATS streaming server to receive notifications using a NATSClient
  • Field Details

    • TRACKING_FILE_NAME_PROPERTY

      public static String TRACKING_FILE_NAME_PROPERTY
      Property for tracking file name
    • UPDATE_SEQUENCE_AFTER_EXCEPTION_PROPERTY

      public static String UPDATE_SEQUENCE_AFTER_EXCEPTION_PROPERTY
      Property on if update sequence should occur after exception
    • SEQUENCE_PROPERTY

      public static String SEQUENCE_PROPERTY
      Property for sequence
    • DEFAULT_TRACKING_FILE_NAME_PROPERTY

      public static String DEFAULT_TRACKING_FILE_NAME_PROPERTY
      Name of deafult tracking file
    • DEFAULT_UPDATE_SEQUENCE_AFTER_EXCEPTION_PROPERTY

      public static String DEFAULT_UPDATE_SEQUENCE_AFTER_EXCEPTION_PROPERTY
      Default state of update after exception
  • Constructor Details

    • NATSStreamingNotificationReceiver

      public NATSStreamingNotificationReceiver()
  • Method Details

    • configure

      public void configure(Config config) throws Exception
      Configures receiver based on included properties
      Specified by:
      configure in interface Configurable
      Overrides:
      configure in class DefaultNotificationReceiver
      Parameters:
      config - The user-defined configuration
      Throws:
      Exception - If required properties are ignored
    • startup

      public void startup() throws Exception
      Does initial tracking file management and subscribes to server With a tracking file, gets the last sequence
      Specified by:
      startup in interface Configurable
      Overrides:
      startup in class DefaultNotificationReceiver
      Throws:
      InterruptedException - if interrupted
      IOException - if IO error occurs
      Exception - if exceptions occur while starting.
    • shutdown

      public void shutdown() throws Exception
      Closes subscription/connection and writes state in tracking file Wraps each statement in a try/catch to ensure each step still happens
      Specified by:
      shutdown in interface Configurable
      Overrides:
      shutdown in class DefaultNotificationReceiver
      Throws:
      IOException - if IO error occurs
      InterruptedException - if interrupted
      TimeoutException - if timeout
      Exception - if exceptions occur while starting.
    • writeTrackingFile

      public void writeTrackingFile() throws Exception
      Writes pertinent configuration information to tracking file
      Throws:
      Exception - if error occurs
    • readTrackingFile

      public javax.json.JsonObject readTrackingFile() throws Exception
      Reads contents of tracking file
      Returns:
      JsonObject containing tracking file contents, or null if file doesn't exist
      Throws:
      Exception - if error occurs
    • onMessage

      public void onMessage(io.nats.streaming.Message message)
      Defines behavior for message receipt. Attempts to process notifications, with configurable behavior for exception handling
      Specified by:
      onMessage in interface io.nats.streaming.MessageHandler
      Parameters:
      message - The message received from the STAN server
    • getTrackingFileName

      public String getTrackingFileName()
      Returns:
      trackingFileName
    • setTrackingFileName

      public void setTrackingFileName(String trackingFileName)
      Parameters:
      trackingFileName - to set
    • getClient

      public NATSClient getClient()
      Returns:
      NATSClient
    • setClient

      public void setClient(NATSClient client)
      Parameters:
      client - NATSClient to set
    • getSubject

      public String getSubject()
      Returns:
      subject
    • setSubject

      public void setSubject(String subject)
      Parameters:
      subject - to set